Skip to content

Commit

Permalink
Make sure the /static working properly. (#2675)
Browse files Browse the repository at this point in the history
  • Loading branch information
arunoda committed Jul 28, 2017
1 parent 23444fc commit 5ce4f43
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
12 changes: 10 additions & 2 deletions server/index.js
Expand Up @@ -171,12 +171,20 @@ export default class Server {
await renderScript(req, res, page, this.renderOpts)
},

'/_next/:path?': async (req, res, params) => {
// 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) => {
const p = join(__dirname, '..', 'client', ...(params.path || []))
await this.serveStatic(req, res, p)
},

'/static/:path?': async (req, res, params) => {
// 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) => {
const p = join(this.dir, 'static', ...(params.path || []))
await this.serveStatic(req, res, p)
}
Expand Down
1 change: 1 addition & 0 deletions test/integration/production/static/data/item.txt
@@ -0,0 +1 @@
item
11 changes: 11 additions & 0 deletions test/integration/production/test/index.test.js
Expand Up @@ -77,4 +77,15 @@ describe('Production Usage', () => {
browser.close()
})
})

describe('Misc', () => {
it('should allow to access /static/ and /_next/', async () => {
// This is a test case which prevent the following issue happening again.
// 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')
})
})
})

0 comments on commit 5ce4f43

Please sign in to comment.