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 4 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
8 changes: 7 additions & 1 deletion src/utils/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ export function defaultContentType (event: CompatibilityEvent, type?: string) {
export function sendRedirect (event: CompatibilityEvent, location: string, code = 302) {
event.res.statusCode = code
event.res.setHeader('Location', location)
return send(event, 'Redirecting to ' + location, MIMES.html)
// 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>Redirecting to <a href=${JSON.stringify(location)}>${location}</a></body>
pi0 marked this conversation as resolved.
Show resolved Hide resolved
</html>`
return send(event, html, MIMES.html)
}

export function appendHeader (event: CompatibilityEvent, name: string, value: string): void {
Expand Down