Skip to content

Commit

Permalink
handle 404s for public files better
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcdodds committed Oct 27, 2023
1 parent e0ceabc commit 726a326
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ app.use(
// more aggressive with this caching.
app.use(express.static('public', { maxAge: '1h' }))

app.get(['/build/*', '/img/*', '/fonts/*', '/favicons/*'], (req, res) => {
// if we made it past the express.static for these, then we're missing something.
// So we'll just send a 404 and won't bother calling other middleware.
return res.status(404).send('Not found')
})

morgan.token('url', (req, res) => decodeURIComponent(req.url ?? ''))
app.use(
morgan('tiny', {
Expand Down

0 comments on commit 726a326

Please sign in to comment.