Skip to content

Commit 606de3b

Browse files
authoredJul 26, 2022
feat(sendRedirect): add refresh meta fallback for static generated responses (#153)
1 parent e27f673 commit 606de3b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed
 

‎src/utils/response.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ export function defaultContentType (event: CompatibilityEvent, type?: string) {
2525
export function sendRedirect (event: CompatibilityEvent, location: string, code = 302) {
2626
event.res.statusCode = code
2727
event.res.setHeader('Location', location)
28-
return send(event, 'Redirecting to ' + location, MIMES.html)
28+
// minimal html document that redirects on client side
29+
const html = `<!DOCTYPE html>
30+
<html>
31+
<head><meta http-equiv="refresh" content="0; url=${encodeURI(location)}"></head>
32+
<body>Redirecting to <a href=${JSON.stringify(location)}>${encodeURI(location)}</a></body>
33+
</html>`
34+
return send(event, html, MIMES.html)
2935
}
3036

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

0 commit comments

Comments
 (0)
Please sign in to comment.