lukeed / lukeed/polka

Cannot mount more than one subapp on the same path

Open
#159 0 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
5.6k
Forks
176
PR merge metrics
No merged PRs in 30d

Description

## Description

When trying to request a route from the second subapp mounted on the same path, it returns 404.

This happens because the first subapp responds with 404 (e.g. calls no match handler) and therefore doesn't switch to the next app, resulting in 404 even though the route is present in another app.

## Code

```js
import App from 'polka'

const router = App()
router.get('/upload', (req, res) => res.end('upload'))

const router2 = App()
router2.get('/product', (req, res) => res.end('product'))

const app = App()

app.use('/api/v1', router, router2)

app.listen(3000, () => console.log(`Started on :3000`))
```

## Expected result

```sh
$ curl localhost:3000/api/v1/product
product
```

Same code but with Express v4 returns the expected result.

## Actual result

```sh
$ curl localhost:3000/api/v1/product
Not Found
```

## Info

- polka: `1.0.0-next.11`
- Node.js: 15.8
- `uname -r`: 5.10.15-1-MANJARO

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the two subapps passed to app.use('/api/v1', router, router2), then trace how the first subapp handles a 404 before the second is reached. Compare the behavior with the reported Express v4 result. Done means the /api/v1/product request reaches router2 while existing unmatched-route behavior remains intact.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.