aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/index.ts22
-rw-r--r--src/middleware.ts5
2 files changed, 18 insertions, 9 deletions
diff --git a/src/index.ts b/src/index.ts
index f764b32..3ff5de7 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,5 +1,6 @@
import { App } from "@tinyhttp/app";
import { logger } from "@tinyhttp/logger";
+import { auth } from "./middleware";
const app = new App();
const port = process.env.PORT ? Number(process.env.PORT) : 3000;
@@ -7,18 +8,21 @@ const port = process.env.PORT ? Number(process.env.PORT) : 3000;
app
.use(logger({
timestamp: {
- format: "YYYY-MM-DDTHH:mm:ssZ[Z]"
- }
+ format: "YYYY-MM-DDTHH:mm:ssZ[Z]",
+ },
}))
- .use(function someMiddleware(_req, _res, next) {
- console.log("Did a request");
- next();
- })
+ .use(auth)
.get("/", (_, res) => {
- res.send("<h1>Hello World</h1>");
+ res.send({ foo: "bar" });
+ })
+ .post("/webhook/start", (_req, res) => {
+ res.send({ webhook: "start" });
+ })
+ .post("/webhook/stop", (_req, res) => {
+ res.send({ webhook: "stop" });
})
- .get("/page/:page/", (req, res) => {
- res.status(200).send(`You just opened ${req.params?.page}`);
+ .post("/scheduler/trigger", (_req, res) => {
+ res.send({ scheduler: "trigger" });
});
console.log(`Serving on http://localhost:${port}`);
diff --git a/src/middleware.ts b/src/middleware.ts
new file mode 100644
index 0000000..bdc006a
--- /dev/null
+++ b/src/middleware.ts
@@ -0,0 +1,5 @@
+import { NextFunction, Request, Response } from "@tinyhttp/app";
+
+export const auth = async (_req: Request, _res: Response, next: NextFunction): Promise<void> => {
+ await next();
+};