Not sure if this one has been addressed but would like to share the problem I'm encountering.
It's a bit long to list everything out here but I will try my best. Alternatively, there is a demo for the said issue which can be found here: https://glitch.com/edit/#!/indigo-sneeze.
// app.js
const app = polka();
// middleware before subApp, but only `apiCore()` runs and `verifyToken` being skipped.
// It's like either one can be run at the same time.
polka.use('/api', verifyToken(), apiCore());
// verify-token.js
function verifyToken() {
return (req, res, next) {
... // Verify token middleware
}
}
// api-core.js
function apiCore() {
return async (req, res) => {
return polka() // subApp consists of multiple route handlers
.post('/create', create())
.post('/view', view());
};
}
Hey! Good timing haha, I _just_ fixed this tonight, along with a couple related issues.
I'll commit and release the changes tomorrow morning. Thanks!
Thank god (and @lukeed)! 馃槃 Then I will wait for the new release. Thank you so much! 馃帀
Lol not a problem.
In the meantime, you can move your verifyToken into your sub-app directly. The next release you can take it back out.
// api-core.js
module.exports = function apiCore() {
// return async (req, res) => { REMOVE THIS LINE
return polka()
.use(verifyToken)
.post('/create', create())
.post('/view', view());
// }; AND THIS
}
You should return the sub-app directly, always. Otherwise you are recreating the app every time.
Ok, bed time 馃憢
It is now working as expected. Thanks for the patch. 馃憤