Public
HTTP (deprecated)
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { fetch } from "https://esm.town/v/std/fetch";
export let blocks_inner = async (request: Request) => {
const [_, user, id, ...file] = new URL(request.url).pathname.split("/");
const gist = await fetch(`https://api.github.com/gists/${id}`).then((r) => r.json());
// res.set("Cache-Control", "public,max-age=64800");
// if (file.filter(Boolean).length) {
// if (gist.files[file.filter(Boolean).join("/")].raw_url.endsWith(".js")) {
// res.set("Content-Type", "application/javascript");
// return res.send(
// await fetch(gist.files[file.filter(Boolean).join("/")].raw_url).then((
// r,
// ) => r.text()),
// );
// }
// return res.redirect(gist.files[file.filter(Boolean).join("/")].raw_url);
// }
// console.log(gist);
const index = gist.files["index.html"];
if (!index) {
// return res.end({ message: "Gist did not contain index.html" });
}
return new Response(
`
${index.content}
`,
{
headers: {
"Content-Type": "text/html",
"Cache-Control": "public,max-age=64800",
},
},
);
};
// Forked from @tmcw.blocks_inner
vlad-blocks.web.val.run
November 29, 2023