Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6f0b0be

Browse files
committed
Add tests for public file handling with basePath
1 parent a4876ae commit 6f0b0be

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/next/next-server/server/next-server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ export default class Server {
787787

788788
// if basePath is defined require it be present
789789
if (basePath) {
790-
if (pathParts[0] !== basePath) return { finished: false }
790+
if (pathParts[0] !== basePath.substr(1)) return { finished: false }
791791
pathParts.shift()
792792
}
793793

test/integration/basepath/test/index.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,17 @@ const runTests = (context, dev = false) => {
135135
})
136136
}
137137

138+
it('should 404 for public file without basePath', async () => {
139+
const res = await fetchViaHTTP(context.appPort, '/data.txt')
140+
expect(res.status).toBe(404)
141+
})
142+
143+
it('should serve public file with basePath correctly', async () => {
144+
const res = await fetchViaHTTP(context.appPort, '/docs/data.txt')
145+
expect(res.status).toBe(200)
146+
expect(await res.text()).toBe('hello world')
147+
})
148+
138149
it('should rewrite with basePath by default', async () => {
139150
const html = await renderViaHTTP(context.appPort, '/docs/rewrite-1')
140151
expect(html).toContain('getServerSideProps')

0 commit comments

Comments
 (0)