Skip to content

Commit

Permalink
Fix headers having check: true behavior when they should not
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Feb 10, 2020
1 parent 247d330 commit 6ade852
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 0 additions & 1 deletion packages/next/next-server/server/next-server.ts
Expand Up @@ -437,7 +437,6 @@ export default class Server {
headers = this.customRoutes.headers.map(r => {
const route = getCustomRoute(r, 'header')
return {
check: true,
match: route.match,
type: route.type,
name: `${route.type} ${route.source} header route`,
Expand Down
13 changes: 13 additions & 0 deletions test/integration/custom-routes/next.config.js
Expand Up @@ -75,6 +75,10 @@ module.exports = {
source: '/api-hello-param/:name',
destination: '/api/hello?name=:name',
},
{
source: '/:path/post-321',
destination: '/with-params',
},
]
},
async redirects() {
Expand Down Expand Up @@ -190,6 +194,15 @@ module.exports = {
},
],
},
{
source: '/:path*',
headers: [
{
key: 'x-something',
value: 'applied-everywhere',
},
],
},
]
},
},
Expand Down
25 changes: 25 additions & 0 deletions test/integration/custom-routes/test/index.test.js
Expand Up @@ -45,6 +45,14 @@ const runTests = (isDev = false) => {
expect(html).toMatch(/multi-rewrites/)
})

it('should not match dynamic route immediately after applying header', async () => {
const res = await fetchViaHTTP(appPort, '/blog/post-321')
expect(res.headers.get('x-something')).toBe('applied-everywhere')

const $ = cheerio.load(await res.text())
expect(JSON.parse($('p').text()).path).toBe('blog')
})

it('should handle chained redirects successfully', async () => {
const res1 = await fetchViaHTTP(appPort, '/redir-chain1', undefined, {
redirect: 'manual',
Expand Down Expand Up @@ -453,6 +461,18 @@ const runTests = (isDev = false) => {
regex: normalizeRegEx('^\\/my-headers(?:\\/(.*))$'),
source: '/my-headers/(.*)',
},
{
headers: [
{
key: 'x-something',
value: 'applied-everywhere',
},
],
regex: normalizeRegEx(
'^(?:\\/((?:[^\\/]+?)(?:\\/(?:[^\\/]+?))*))?$'
),
source: '/:path*',
},
],
rewrites: [
{
Expand Down Expand Up @@ -553,6 +573,11 @@ const runTests = (isDev = false) => {
regex: normalizeRegEx('^\\/api-hello-param(?:\\/([^\\/]+?))$'),
source: '/api-hello-param/:name',
},
{
destination: '/with-params',
regex: normalizeRegEx('^(?:\\/([^\\/]+?))\\/post-321$'),
source: '/:path/post-321',
},
],
dynamicRoutes: [
{
Expand Down

0 comments on commit 6ade852

Please sign in to comment.