Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make redirect easier when visit a non-based page #4618

Merged
merged 1 commit into from Aug 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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