We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What if I wanted to run some code on every request/route? For example, logging the headers to the console.
Is there any way to do this without having to put the code in every handler?
Thanks for the great library!
The text was updated successfully, but these errors were encountered:
Recommended at the bottom of this comment is to use decorators as middleware. I suppose I could wrap router with log like so:
router
log
const { router, get } = require('microrouter') const { log } = require('./my-middleware') module.exports = log(router( get('/hello/:who', hello), get('/*', notfound) ))
I'll give this a shot.
Sorry, something went wrong.
The following higher order function worked with the above example:
const log = fn => (req, res) => { console.log(req.headers) fn(req, res) }
No branches or pull requests
What if I wanted to run some code on every request/route? For example, logging the headers to the console.
Is there any way to do this without having to put the code in every handler?
Thanks for the great library!
The text was updated successfully, but these errors were encountered: