lukeed / lukeed/polka

App mount path stripped to a of cardinality of 1

Open
#36 11 comments 5 reactions 0 assignees View on GitHub
has fix
Dominant language
JavaScript
Stars
5.6k
Forks
176
PR merge metrics
No merged PRs in 30d

Description

Hey, thanks for writing this. I'm a huge fan of Express/NodeJS web service alternatives.

It looks like the cardinality of the mounting path of each middleware/app is stripped to a limit of 1.

Example:

```
const app = require('polka')();

app
.use('/foo/bar/baz', function(_, res) {
res.end();
})
.listen(3000);
```

If I visit localhost:3000/foo/bar/baz, I will get a 404. I think this is because of the value function, it checks for the first slash after the leading. So, if I provide:

`/foo/bar/baz`, the first slash is the zeroeth position of the string and the string itself is stripped to `foo`.

Is this by design? If this is done in error, it can easily be fixed with some language around how the trailing slash should be considered, or by using `lastIndexOf`. It also works if I just don't consider the value function at all.

Additionally, it looks like there is a `mountpath` instance property, but it is not set from the constructor, perhaps this could be used in some way?

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the nested mount case from the issue and trace the value function involved in stripping the mounting path. Inspect the mountpath instance property as well; done means /foo/bar/baz reaches the middleware instead of returning a 404, with the intended mount path preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.