aboutsummaryrefslogtreecommitdiffstats
path: root/src/index.ts
blob: f764b321a2d29f5bba78475c7a8e412326445a72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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);