Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/commands/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ async function startDevServer(settings, log) {
name: 'netlify-dev',
port: settings.frameworkPort,
templates: {
notFound: '404.html',
notFound: path.join(settings.dist, '404.html'),
},
})

Expand Down
25 changes: 25 additions & 0 deletions tests/command.dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,31 @@ test('should return 404.html if exists for non existing routes', async t => {
})
})

test('should return 404.html from publish folder if exists for non existing routes', async t => {
await withSiteBuilder('site-with-shadowing-404-in-publish-folder', async builder => {
builder
.withContentFile({
path: 'public/404.html',
content: '<h1>404 - My Custom 404 Page</h1>',
})
.withNetlifyToml({
config: {
build: {
publish: 'public/',
},
},
})

await builder.buildAsync()

await withDevServer({ cwd: builder.directory }, async server => {
const response = await fetch(`${server.url}/non-existent`)
t.is(response.status, 404)
t.is(await response.text(), '<h1>404 - My Custom 404 Page</h1>')
})
})
})

test('should return 404 for redirect', async t => {
await withSiteBuilder('site-with-shadowing-404-redirect', async builder => {
builder
Expand Down