diff --git a/middleware.ts b/middleware.ts new file mode 100644 index 0000000..6ae92c7 --- /dev/null +++ b/middleware.ts @@ -0,0 +1,24 @@ +import { Application, Context, Next, Router } from "jsr:@oak/oak"; + +interface HelloWorldState { + hello?: string; + world?: string; +} +async function hello(ctx: Context, next: Next) { + ctx.state.hello = "Hello"; + await next(); +} +async function world(ctx: Context, next: Next) { + ctx.state.world = "world"; + await next(); +} + +const router = new Router(); +router.get("/hello", hello, world, (ctx) => { + ctx.response.body = `${ctx.state.hello}, ${ctx.state.world}!`; +}); + +const app = new Application(); +app.use(router.routes()); +app.use(router.allowedMethods()); +app.listen({ port: 8000 });