Last active
May 26, 2021 08:01
-
-
Save kt3k/16531691a8533a0f965582a48b3b1922 to your computer and use it in GitHub Desktop.
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
const dirData: Record<string, Uint8Array> = {}; | |
dirData["/bar.ts"] = [Uint8Array.from(atob("Y29uc29sZS5sb2coImJhciIpOwo="), (c) => c.charCodeAt(0)), "text/typescript"]; | |
dirData["/foo.txt"] = [Uint8Array.from(atob("Zm9vCg=="), (c) => c.charCodeAt(0)), "text/plain"]; | |
addEventListener("fetch", (e) => { | |
const { pathname } = new URL(e.request.url); | |
const data = dirData[pathname]; | |
if (data) { | |
const [bytes, mediaType] = data; | |
e.respondWith(new Response(bytes, { headers: { "content-type": mediaType } })); | |
return; | |
} | |
e.respondWith(new Response("404 Not Found", { status: 404 })); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment