未验证 提交 f81c5d54 编写于 作者: J Joe Haddad 提交者: GitHub

Match `public/static/` folder before `static/` (#8986)

* Test `public/static/` folder

* Public routes should be matched before static catch-all
上级 7674bab7
......@@ -219,6 +219,10 @@ export default class Server {
}
protected generateRoutes(): Route[] {
const publicRoutes = fs.existsSync(this.publicDir)
? this.generatePublicRoutes()
: []
const routes: Route[] = [
{
match: route('/_next/static/:path*'),
......@@ -270,6 +274,7 @@ export default class Server {
await this.render404(req, res, parsedUrl)
},
},
...publicRoutes,
{
// It's very important to keep this route's param optional.
// (but it should support as many params as needed, separated by '/')
......@@ -294,10 +299,6 @@ export default class Server {
},
]
if (fs.existsSync(this.publicDir)) {
routes.push(...this.generatePublicRoutes())
}
if (this.nextConfig.useFileSystemPublicRoutes) {
this.dynamicRoutes = this.getDynamicRoutes()
......
......@@ -6,6 +6,9 @@ export default context => {
it('should allow access to public files', async () => {
const data = await renderViaHTTP(context.appPort, '/data/data.txt')
expect(data).toBe('data')
const legacy = await renderViaHTTP(context.appPort, '/static/legacy.txt')
expect(legacy).toMatch(`new static folder`)
})
})
}
......@@ -377,8 +377,10 @@ describe('Production Usage', () => {
it('Should allow access to public files', async () => {
const data = await renderViaHTTP(appPort, '/data/data.txt')
const file = await renderViaHTTP(appPort, '/file')
const legacy = await renderViaHTTP(appPort, '/static/legacy.txt')
expect(data).toBe('data')
expect(file).toBe('test')
expect(legacy).toMatch(`new static folder`)
})
it('should reload the page on page script error', async () => {
......
......@@ -56,6 +56,9 @@ describe('Serverless', () => {
it('should serve file from public folder', async () => {
const content = await renderViaHTTP(appPort, '/hello.txt')
expect(content.trim()).toBe('hello world')
const legacy = await renderViaHTTP(appPort, '/static/legacy.txt')
expect(legacy).toMatch(`new static folder`)
})
it('should render the page with dynamic import', async () => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册