Skip to content

Commit

Permalink
feat: make redirect easier when visit a non-based page (#4618)
Browse files Browse the repository at this point in the history
  • Loading branch information
CHOYSEN committed Aug 16, 2021
1 parent 01b3a4c commit b97afa7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/vite/src/node/server/middlewares/base.ts
Expand Up @@ -36,10 +36,13 @@ export function baseMiddleware({
return
} else if (req.headers.accept?.includes('text/html')) {
// non-based page visit
res.statusCode = 404
const redirectPath = base + url.slice(1)
res.writeHead(404, {
'Content-Type': 'text/html'
})
res.end(
`The server is configured with a public base URL of ${base} - ` +
`did you mean to visit ${base}${url.slice(1)} instead?`
`did you mean to visit <a href="${redirectPath}">${redirectPath}</a> instead?`
)
return
}
Expand Down

0 comments on commit b97afa7

Please sign in to comment.