Skip to content

Commit

Permalink
Add check that dynamic route is API route in handleApiRequest (#10360)
Browse files Browse the repository at this point in the history
* Add failing test case

* Add check that dynamic route is API route in handleApiRequest
  • Loading branch information
ijjk committed Feb 1, 2020
1 parent afc278f commit 1674f2d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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

0 comments on commit 1674f2d

Please sign in to comment.