Skip to content

Commit

Permalink
feat(sendRedirect): add refresh meta fallback for static generated re…
Browse files Browse the repository at this point in the history
…sponses (#153)
  • Loading branch information
danielroe authored Jul 26, 2022
1 parent e27f673 commit 606de3b
Showing 1 changed file with 7 additions and 1 deletion.
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)}>${encodeURI(location)}</a></body>
</html>`
return send(event, html, MIMES.html)
}

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

0 comments on commit 606de3b

Please sign in to comment.