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 default async function(request: Request) {
const url = new URL(request.url);
const h = url.searchParams.get("tdestination");
if (h) {
const resp = await fetch(decodeURIComponent(url.searchParams.get("tdestination")), {
method: request.method,
body: request.body,
headers: request.headers,
redirect: "manual",
});
return new Response(resp.body, { status: resp.status, headers: resp.headers });
}
else {
const resp = await fetch(decodeURIComponent(url.searchParams.get("destination")), {
method: request.method,
body: request.body,
headers: request.headers,
});
// if (resp.headers.get("content-type") === "application/vnd.apple.mpegurl") {
// const proxyUrl = decodeURIComponent(url.searchParams.get("destination"));
// const baseUrl = proxyUrl.replace(proxyUrl.split("/").pop(), "");
// const base = `https://tempguy-copperscorpion.web.val.run?destination=`;
// const content = await resp.text();
// let modifiedLines = content.split("\n").map((line) => {
// if (!line.startsWith("#")) {
// return base + encodeURIComponent(baseUrl + line);
// }
// return line; // Keep the original line if it starts with "#"
// });
// const modifiedContent = modifiedLines.join("\n");
// return new Response(modifiedContent, { status: resp.status, headers: resp.headers });
// }
return new Response(resp.body, { status: resp.status, headers: resp.headers });
}
}
tempguy-copperscorpion.web.val.run
July 26, 2024