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
37
38
// NOTE: This doesn't work great.
const valDomain = "chet-notionSiteProxy.web.val.run";
const notionPage = "https://chetcorcos.notion.site/0e27612403084b2fb4a3166edafd623a";
export default async function(req: Request): Promise<Response> {
const notionUrl = new URL(notionPage);
const notionDomain = notionUrl.host;
const url = new URL(req.url);
if (url.pathname === "/") {
url.host = valDomain;
url.pathname = notionUrl.pathname;
return Response.redirect(url);
}
url.host = notionDomain;
const response = await fetch(url, req);
const contents = await response.text();
const fixed = contents
.split(notionDomain)
.join(valDomain)
.split("notion.so")
.join("val.run")
.split("notion.site")
.join("val.run");
const headers = new Headers(response.headers);
headers.delete("Content-Security-Policy");
headers.set("Access-Control-Allow-Origin", "*");
headers.set("Access-Control-Allow-Methods", "GET, HEAD, POST,PUT, OPTIONS");
headers.set("Access-Control-Allow-Headers", "Content-Type");
const proxyRepsonse = new Response(fixed, { ...response, headers });
return proxyRepsonse;
}
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.