Routes folder structure

This commit is contained in:
Kalle (Sendou)
2021-10-23 17:14:08 +03:00
parent 7f77dca0e7
commit 05bcc0a386
3 changed files with 22 additions and 11 deletions

View File

@@ -1,18 +1,14 @@
import { App } from "@tinyhttp/app";
import { logger } from "@tinyhttp/logger";
import routes from "../src/routes/index";
const app = new App();
const PORT = 3000;
app
.use(logger())
.get("/", (_, res) => void res.send("<h1>Hello World</h1>"))
.get("/page/:page/", (req, res) => {
res.status(200).send(`
<h1>Some cool page</h1>
<h2>URL</h2>
${req.url}
<h2>Params</h2>
${JSON.stringify(req.params, null, 2)}
`);
})
.listen(3000);
.use(routes)
.listen(PORT, () =>
console.log(`Server ready at: https://localhost:${PORT}`)
);

View File

@@ -0,0 +1,8 @@
import { App } from "@tinyhttp/app";
import tournament from "./tournaments.routes";
const routes = new App();
routes.use("/tournaments", tournament);
export default routes;

View File

@@ -0,0 +1,7 @@
import { App } from "@tinyhttp/app";
const app = new App();
app.get("/", (req, res) => res.send("Welcome"));
export default app;