Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,12 @@ ${
.replace(/www\\.notion\\.so/g, MY_DOMAIN);
}

const PAGE_FETCH_HEADERS = {
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'accept-language': 'en-US,en;q=0.9'
};

async function fetchAndApply(request) {
if (request.method === 'OPTIONS') {
return handleOptions(request);
Expand Down Expand Up @@ -630,19 +636,15 @@ ${
const pageId = SLUG_TO_PAGE[matchedSlug];
url.pathname = '/' + pageId;
response = await fetch(url.toString(), {
body: request.body,
headers: request.headers,
method: request.method,
headers: PAGE_FETCH_HEADERS,
});
response = new Response(response.body, response);
response.headers.delete('Content-Security-Policy');
response.headers.delete('X-Content-Security-Policy');
return appendJavascript(response, SLUG_TO_PAGE, matchedSlug, url);
} else {
response = await fetch(url.toString(), {
body: request.body,
headers: request.headers,
method: request.method,
headers: PAGE_FETCH_HEADERS,
});
response = new Response(response.body, response);
response.headers.delete('Content-Security-Policy');
Expand All @@ -654,8 +656,7 @@ ${
const notFoundUrl = new URL(url);
notFoundUrl.pathname = '/' + CUSTOM_404_PAGE_ID;
const notFoundResponse = await fetch(notFoundUrl.toString(), {
headers: request.headers,
method: 'GET',
headers: PAGE_FETCH_HEADERS,
});
// Return custom 404 page content with 404 status
response = new Response(notFoundResponse.body, {
Expand Down