Commit 10241fe6 authored by Arunoda Susiripala's avatar Arunoda Susiripala Committed by GitHub

Fix the route redirect error when we've multiple path params. (#2652)

For an example, with a URL like: /static/data/hello.txt
parent 84de7f93
...@@ -200,17 +200,19 @@ export default class Server { ...@@ -200,17 +200,19 @@ export default class Server {
}, },
// It's very important keep this route's param optional. // It's very important keep this route's param optional.
// (but it should support as many as params, seperated by '/')
// Othewise this will lead to a pretty simple DOS attack. // Othewise this will lead to a pretty simple DOS attack.
// See more: https://github.com/zeit/next.js/issues/2617 // See more: https://github.com/zeit/next.js/issues/2617
'/_next/:path?': async (req, res, params) => { '/_next/:path*': async (req, res, params) => {
const p = join(__dirname, '..', 'client', ...(params.path || [])) const p = join(__dirname, '..', 'client', ...(params.path || []))
await this.serveStatic(req, res, p) await this.serveStatic(req, res, p)
}, },
// It's very important keep this route's param optional. // It's very important keep this route's param optional.
// (but it should support as many as params, seperated by '/')
// Othewise this will lead to a pretty simple DOS attack. // Othewise this will lead to a pretty simple DOS attack.
// See more: https://github.com/zeit/next.js/issues/2617 // See more: https://github.com/zeit/next.js/issues/2617
'/static/:path?': async (req, res, params) => { '/static/:path*': async (req, res, params) => {
const p = join(this.dir, 'static', ...(params.path || [])) const p = join(this.dir, 'static', ...(params.path || []))
await this.serveStatic(req, res, p) await this.serveStatic(req, res, p)
} }
......
...@@ -107,6 +107,8 @@ describe('Production Usage', () => { ...@@ -107,6 +107,8 @@ describe('Production Usage', () => {
// See: https://github.com/zeit/next.js/issues/2617 // See: https://github.com/zeit/next.js/issues/2617
await renderViaHTTP(appPort, '/_next/') await renderViaHTTP(appPort, '/_next/')
await renderViaHTTP(appPort, '/static/') await renderViaHTTP(appPort, '/static/')
const data = await renderViaHTTP(appPort, '/static/data/item.txt')
expect(data).toBe('item')
}) })
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment