Skip to content

Commit

Permalink
Fix API route matched as page on Windows in dev (#46238)
Browse files Browse the repository at this point in the history
Use `path.join` to build the path instead of a template string. This ensures the format is correct on all platforms. Currently it incorrectly matches API routes as pages due to forward slashes in `/api/` being added to the end, which doesn't work on Windows.

This caused the dev server to incorrectly log `Duplicate page detected`.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
  • Loading branch information
hanneslund authored Feb 22, 2023
1 parent 1567f42 commit e09feab
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class DevPagesRouteMatcherProvider extends FileCacheRouteMatcherProvider<
// so we need to include the pages directory.

// TODO: could path separator normalization be needed here?
if (filename.startsWith(`${this.pagesDir}/api/`)) return false
if (filename.startsWith(path.join(this.pagesDir, '/api/'))) return false

for (const extension of this.extensions) {
// We can also match if we have `pages/api.${extension}`, so check to
Expand Down

0 comments on commit e09feab

Please sign in to comment.