Public
Express
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
import { fetch } from "https://esm.town/v/std/fetch";
export let blocks_inner = async (req, res) => {
const [_, user, id, ...file] = req.path.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 res.status(200).send(`<html>
<body>
${index.content}
</body>
</html>
`);
};
// Forked from @tmcw.blocks_inner
vlad-blocks_inner.express.val.run
November 29, 2023