Repository: next.js
Issue: Setting useFileSystemPublicRoutes to false breaks custom server rendering (404)
Labels: bug,Output (export/standalone),Navigation

### Link to the code that reproduces this issue

[Codesandbox reproduction link](https://codesandbox.io/p/devbox/nextjs-custom-server-no-fs-routes-forked-hv8ct2?layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522clqffftax00053b6gy4nglmyq%2522%252C%2522sizes%2522%253A%255B70%252C30%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522clqffftax00023b6gto8p7qpr%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522clqffftax00033b6g9ewfozst%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522clqffftax00043b6g8w8y590m%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B60%252C40%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clqffftax00023b6gto8p7qpr%2522%253A%257B%2522id%2522%253A%2522clqffftax00023b6gto8p7qpr%2522%252C%2522activeTabId%2522%253A%2522clqffszxx00023b6gw9f6ffzw%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clqffftax00013b6gkp04j453%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252FREADME.md%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%252C%257B%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252F.codesandbox%252Ftasks.json%2522%252C%2522id%2522%253A%2522clqffjt0d00g43b6g4rqi3epf%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%252C%257B%2522id%2522%253A%2522clqffszxx00023b6gw9f6ffzw%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522initialSelections%2522%253A%255B%257B%2522startLineNumber%2522%253A12%252C%2522startColumn%2522%253A44%252C%2522endLineNumber%2522%253A12%252C%2522endColumn%2522%253A44%257D%255D%252C%2522filepath%2522%253A%2522%252Fserver.ts%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%255D%257D%252C%2522clqffftax00043b6g8w8y590m%2522%253A%257B%2522id%2522%253A%2522clqffftax00043b6g8w8y590m%2522%252C%2522tabs%2522%253A%255B%257B%2522type%2522%253A%2522TASK_PORT%2522%252C%2522taskId%2522%253A%2522dev%2522%252C%2522port%2522%253A3000%252C%2522id%2522%253A%2522clqffh4tv004r3b6gtlhog54w%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522path%2522%253A%2522%252Fa%2522%257D%255D%252C%2522activeTabId%2522%253A%2522clqffh4tv004r3b6gtlhog54w%2522%257D%252C%2522clqffftax00033b6g9ewfozst%2522%253A%257B%2522id%2522%253A%2522clqffftax00033b6g9ewfozst%2522%252C%2522activeTabId%2522%253A%2522clqffgwgm003g3b6gtvrwp3s2%2522%252C%2522tabs%2522%253A%255B%257B%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522dev%2522%252C%2522id%2522%253A%2522clqffgwgm003g3b6gtvrwp3s2%2522%252C%2522mode%2522%253A%2522permanent%2522%257D%255D%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Atrue%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D)

### To Reproduce

(For ease see linked reproduction which has these steps already performed)

1. Copy the custom-server example - https://github.com/vercel/next.js/tree/canary/examples/custom-server
2. Set `useFileSystemPublicRoutes: false` within a `next.config.js`
3. Add explicit route handling to the server e.g. `if "/a" -> app.render(req, res, "/a")`
4. Run the server, and access `/a`, `/b`, or `/`

### Current vs. Expected behavior

### Current behaviour
All routes will produce the generic nextJS 404 page

### Expected behaviour
Matching code from `/pages` is rendered

### Verify canary release

- [X] I verified that the issue exists in the latest Next.js canary release

### Provide environment information

```bash
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.5.0: Thu Jun  8 22:21:34 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T8112
Binaries:
  Node: 18.18.0
  npm: 9.8.1
  Yarn: N/A
  pnpm: 8.12.1
Relevant Packages:
  next: 14.0.5-canary.23
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 4.9.5
Next.js Config:
  output: N/A
```


### Which area(s) are affected? (Select all that apply)

Routing (next/router, next/navigation, next/link), Standalone mode (output: "standalone")

### Additional context

`next@13.4.12` does not include this bug, it seems to be introduced in `next@13.4.13`, (including `next@13.4.13-canary.0`).

I saw there was quite a bit of refactoring around the routing as part of this patch version so thinking something related may have introduced it, e.g. 1398de997 or d8f4fa894