express-async-await
express-async-await copied to clipboard
How can apply wrap for express Router
Hi I tried this, but does't work, could you pls help
// routers/user.js
var express = require('express');
var router = express.Router();
router.get('/users', async func1, async func2);
module.exports = router;
// server.js
let expressaa = require('./lib/wrapAsyncAwait')
let express = require('express')
let app = expressaa(express())
app.use('/', require('./routers/user'));
ah, I figured it works when wrap expressaa(express.Router())
in routers/user.js
is it correct way?
Hi @nvcken that works! On the other end, I recently found another library that does the same with a nicer hack -- I'd recommend you to check it out!
Yes @nvcken, as the react router is an express app itself you can monkey patch it in the same way. I 've opened a pr #4 to add docs and example for this. @odino I missed this thread and the closed one you referred, feel free to close my PR as well then