express-async-await icon indicating copy to clipboard operation
express-async-await copied to clipboard

How can apply wrap for express Router

Open nvcken opened this issue 6 years ago • 3 comments

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'));

nvcken avatar Nov 15 '17 02:11 nvcken

ah, I figured it works when wrap expressaa(express.Router()) in routers/user.js is it correct way?

nvcken avatar Nov 15 '17 02:11 nvcken

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!

odino avatar Nov 15 '17 05:11 odino

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

nickbalestra avatar Dec 31 '17 00:12 nickbalestra