Skip to content

Instantly share code, notes, and snippets.

@tbremer
Created November 3, 2020 19:47
Show Gist options
  • Save tbremer/ab06dd2b30490ce517f5c2840b243241 to your computer and use it in GitHub Desktop.
Save tbremer/ab06dd2b30490ce517f5c2840b243241 to your computer and use it in GitHub Desktop.
Serve Custom Headers
{
"date": 1604432085011
}
<!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>
{
"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