Created
November 3, 2020 19:47
-
-
Save tbremer/ab06dd2b30490ce517f5c2840b243241 to your computer and use it in GitHub Desktop.
Serve Custom Headers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"date": 1604432085011 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
</head> | |
<body> | |
Below should be the file contents of the file set in the cookie | |
<section> | |
<pre><code id="data-dump">Loading…</code></pre> | |
</section> | |
<script> | |
const fileCookie = document.cookie.split('&').find(cookie => cookie.startsWith('file=')) | |
const [,fileName] = fileCookie.split('='); | |
fetch(`/${fileName}`) | |
.then(r => r.json()) | |
.then(fileData => { | |
const node = document.getElementById('data-dump'); | |
node.innerText = JSON.stringify(fileData, null, 2); | |
}) | |
console.log({fileCookie, fileName}) | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"headers": [{ | |
"source": "/**/*", | |
"headers": [{ | |
"key": "Set-Cookie", | |
"value": "file=foo.json" | |
}] | |
}] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment