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
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);
}
const index = gist.files["index.html"];
if (!index) {
return res.end({ message: "Gist did not contain index.html" });
}
return res.send(index.content.replace("http://d3js.org", "https://d3js.org"));
};
tmcw-blocks_inner.express.val.run
October 23, 2023