Compatibility with Express syntax
See original GitHub issueCurrently the middleware serve-static
as in the examples is implemented as
polka()
.get('/', serve)
.use('assets', serve)
.get('/health', (req, res) => {
res.end('OK');
})
.listen(PORT).then(_ => {
console.log(`> Running on localhost:${PORT}`);
});
A simple method, like in usage by express
polka()
.use(serve)
.listen(PORT).then(_ => {
console.log(`> Running on localhost:${PORT}`);
});
is not possible currently, because bwares
and apps
require a base(for subapp) and the URL’s are being stripped off in favour for subapps, so serve-static
fails to handle the requests (I might be doing something wrong here, if any please help).
And as in subapps, the URL’s are being stripped untill the first slash(/
) to obtain the base
. For requests like /sw.js
, the sw.js
is considered the base
, and thus the requests are redirected to /sw.js/
. This behaviour is expected but, generally(might be personally) it feels proper to have all the requests managed by the middleware. Simply being able to register middlewares to handle requests (not like compression, body-parser etc. though) is helpful.
Issue Analytics
- State:
- Created 6 years ago
- Comments:22 (11 by maintainers)
Top GitHub Comments
Helps that you actually told me what you were doing, instead of kinda-useless demos that implied behaviors that didn’t actually have. 😆
I’ll look into benchmarking this & seeing that nothing inadvertently breaks.
Thanks~!
This is the commit with the fix: 3120116882047c76040607b5c2984c6bb2c378ca
It wasn’t quite as easy as the snippet above, but it works now. I also included tests & a new example to illustrate the changes.
Thanks again 🙌