From 10241fe610ea0d51f13a6d0a3847cb89805e23df Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Wed, 26 Jul 2017 22:31:49 +0530 Subject: [PATCH] Fix the route redirect error when we've multiple path params. (#2652) For an example, with a URL like: /static/data/hello.txt --- server/index.js | 6 ++++-- test/integration/production/static/data/item.txt | 1 + test/integration/production/test/index.test.js | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 test/integration/production/static/data/item.txt diff --git a/server/index.js b/server/index.js index 139cd64c..7ddce95c 100644 --- a/server/index.js +++ b/server/index.js @@ -200,17 +200,19 @@ export default class Server { }, // 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. // 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 || [])) await this.serveStatic(req, res, p) }, // 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. // 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 || [])) await this.serveStatic(req, res, p) } diff --git a/test/integration/production/static/data/item.txt b/test/integration/production/static/data/item.txt new file mode 100644 index 00000000..a7130742 --- /dev/null +++ b/test/integration/production/static/data/item.txt @@ -0,0 +1 @@ +item \ No newline at end of file diff --git a/test/integration/production/test/index.test.js b/test/integration/production/test/index.test.js index 5e06271f..5128f707 100644 --- a/test/integration/production/test/index.test.js +++ b/test/integration/production/test/index.test.js @@ -107,6 +107,8 @@ describe('Production Usage', () => { // See: https://github.com/zeit/next.js/issues/2617 await renderViaHTTP(appPort, '/_next/') await renderViaHTTP(appPort, '/static/') + const data = await renderViaHTTP(appPort, '/static/data/item.txt') + expect(data).toBe('item') }) })