question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compatibility with Express syntax

See original GitHub issue

Currently 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:closed
  • Created 6 years ago
  • Comments:22 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
lukeedcommented, Feb 6, 2018

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~!

0reactions
lukeedcommented, Feb 7, 2018

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 🙌

Read more comments on GitHub >

github_iconTop Results From Across the Web

Routing - Express.js
Express Route Tester is a handy tool for testing basic Express routes, although it does not support pattern matching. Query strings are not...
Read more >
How to enable ES6 (and beyond) syntax with Node and Express
We need a package that translates ES6 and above syntax to ES5 code. ES5 code is the JS syntax style that is readable...
Read more >
Express.js & MongoDB | Support & Compatibility
Express is an unopinionated framework that is easy to learn and use. You can extend it as you like and you can use...
Read more >
Express/Node introduction - Learn web development | MDN
While Express itself is fairly minimalist, developers have created compatible middleware packages to address almost any web development ...
Read more >
Get started with ES6 JavaScript for writing Node.js using ...
Tagged with node, javascript, express, babel. ... backend development using Node.js, and you had to go back to the old-fashioned ES5 syntax?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found