diff options
| author | Jan Tuomi <jan.tuomi@valuemotive.com> | 2021-04-18 16:43:31 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan.tuomi@valuemotive.com> | 2021-04-18 16:45:06 +0300 |
| commit | 8d26eb5b5e6b0bac4298ca0b2946193a841eade5 (patch) | |
| tree | ba3ba3b996ebb71caba7afbd43d1736a2c55bb6a /src | |
Initial commit
Diffstat (limited to 'src')
| -rw-r--r-- | src/index.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..f764b32 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,25 @@ +import { App } from "@tinyhttp/app"; +import { logger } from "@tinyhttp/logger"; + +const app = new App(); +const port = process.env.PORT ? Number(process.env.PORT) : 3000; + +app + .use(logger({ + timestamp: { + format: "YYYY-MM-DDTHH:mm:ssZ[Z]" + } + })) + .use(function someMiddleware(_req, _res, next) { + console.log("Did a request"); + next(); + }) + .get("/", (_, res) => { + res.send("<h1>Hello World</h1>"); + }) + .get("/page/:page/", (req, res) => { + res.status(200).send(`You just opened ${req.params?.page}`); + }); + +console.log(`Serving on http://localhost:${port}`); +app.listen(port); |
