提交 7a728d69 编写于 作者: V Vitaliy 提交者: Joe Haddad

Serve `public/` folder when page routes are disabled (#10169)

Co-authored-by: NJJ Kasper <jj@jjsweb.site>
Co-authored-by: NJoe Haddad <timer150@gmail.com>
上级 b95214e2
......@@ -520,12 +520,12 @@ export default class Server {
)
}
const catchAllRoute: Route = {
const catchPublicDirectoryRoute: Route = {
match: route('/:path*'),
type: 'route',
name: 'Catchall render',
name: 'Catch public directory route',
fn: async (req, res, params, parsedUrl) => {
const { pathname, query } = parsedUrl
const { pathname } = parsedUrl
if (!pathname) {
throw new Error('pathname is undefined')
}
......@@ -537,6 +537,24 @@ export default class Server {
}
}
return {
finished: false,
}
},
}
routes.push(catchPublicDirectoryRoute)
const catchAllRoute: Route = {
match: route('/:path*'),
type: 'route',
name: 'Catchall render',
fn: async (req, res, params, parsedUrl) => {
const { pathname, query } = parsedUrl
if (!pathname) {
throw new Error('pathname is undefined')
}
if (params?.path?.[0] === 'api') {
const handled = await this.handleApiRequest(
req as NextApiRequest,
......
......@@ -54,4 +54,11 @@ describe('FileSystemPublicRoutes', () => {
const body = await res.text()
expect(body).toMatch(/exportpathmap was here/)
})
it('should route to public folder files', async () => {
const res = await fetch('/hello.txt')
expect(res.status).toBe(200)
const body = await res.text()
expect(body).toMatch(/hello/)
})
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册