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(sendRedirect): add refresh meta fallback for static generated responses #153

Merged
merged 5 commits into from
Jul 26, 2022
Merged
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/utils/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function sendRedirect (event: CompatibilityEvent, location: string, code
event.res.statusCode = code
event.res.setHeader('Location', location)
// minimal html document that redirects on client side
const html = `<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=${encodeURI(location)}"></head><body></body></html>`
const html = `<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=${encodeURI(location)}"></head><body><noscript>Redirecting to <a href=${JSON.stringify(location)}>${location}</a></noscript></body></html>`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think meta also works in case of scripts being disabled :) What i meant was to preserve current behavior of display redirect link while navigation happens (instead of blank screen)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I think it does too. I was thinking more of a search engine. I still think it's a worse UX to have it flash on screen (because it's meant to be an SSR redirect, and at least the white screen suggests it's 'still loading'), but will update.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe search engines should pick it up as a normal redirect.

I have some better ideas to handle static redirects with nitro btw once we have better route rules. It can be integrated with native provider routing and extract redirects.

return send(event, html, MIMES.html)
}

Expand Down