profile
viewpoint

Ask questionsMiddleware not working when using a router

I placed middleware after a router and it never gets called for some reason. I want to log the status of a response. Below is the code used.

import { Application, Router } from "https://deno.land/x/oak/mod.ts";

const app = new Application();

const router = new Router();
router.get("/", async (context, next) => {
  context.response.body = "hello world";
  await next();
});

app.use(router.routes());
app.use(router.allowedMethods());

app.use(async (context, next) => {
  console.log(context.response.toServerResponse().status);
  await next();
});

await app.listen({ port: 8000 });
oakserver/oak

Answer questions kitsonk

If I change response.status to a getter, I can put logic in there that would determine based on the current state of the response, what the .status would be if not set.

useful!

Related questions

No questions were found.
Github User Rank List