Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check that dynamic route is API route in handleApiRequest #10360

Merged
merged 2 commits into from Feb 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/next/next-server/server/next-server.ts
Expand Up @@ -644,7 +644,7 @@ export default class Server {
if (!pageFound && this.dynamicRoutes) {
for (const dynamicRoute of this.dynamicRoutes) {
params = dynamicRoute.match(pathname)
if (params) {
if (dynamicRoute.page.startsWith('/api') && params) {
page = dynamicRoute.page
pageFound = true
break
Expand Down
6 changes: 6 additions & 0 deletions test/integration/dynamic-routing/test/index.test.js
Expand Up @@ -61,6 +61,12 @@ function runTests(dev) {
expect(html).toMatch(/blog post.*321.*comment.*123/i)
})

it('should not error when requesting dynamic page with /api', async () => {
const res = await fetchViaHTTP(appPort, '/api')
expect(res.status).toBe(200)
expect(await res.text()).toMatch(/this is.*?api/i)
})

it('should render dynamic route with query', async () => {
const browser = await webdriver(appPort, '/')
await browser.elementByCss('#view-post-1-with-query').click()
Expand Down