Middleware not working when using a router
See original GitHub issueI 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 });
Issue Analytics
- State:
- Created 3 years ago
- Comments:9
Top Results From Across the Web
express global middleware not being called - node.js
Thanks very much - this did the trick! My takeaway is that app.router has to be the last global middleware added before defining...
Read more >Middleware not working - Laracasts
Middleware not working. Around all of my routes I have but I am still able to access all of my routes. Copy Code...
Read more >Using middleware - Express.js
To skip the rest of the middleware functions from a router middleware stack, call next('route') to pass control to the next route. NOTE:...
Read more >koa-router middleware not working on route level - Reddit
koa-router middleware not working on route level. hey all, not sure if this is the correct subreddit to be posting to, but neither...
Read more >Complete Guide to Express Middleware - Reflectoring
We call app.use() to add a middleware function to our Express ... project for running our examples of using middleware functions in Express....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
you should write middleware before route. you can write
@lewislbr https://oakserver.github.io/oak/#control-the-execution-of-middleware