-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabout.js
32 lines (27 loc) · 1.06 KB
/
about.js
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
async function handleRequest(request) {
try {
const { pathname } = new URL(request.url);
if (pathname.startsWith('/about')) {
const response = await fetch(request);
const contentType = response.headers.get('Content-Type');
if (contentType.startsWith('text/html')) {
return rewriter.transform(response);
} else {
return response;
}
}
} catch(err) {
return new Response(err.stack, { status: 500 })
}
}
class AboutRewriter {
text(text) {
if (text.text.includes('summary of rules you need to follow')) {
text.replace('nelson.social is an online space dedicated to the community of Nelson, BC. Please carefully read our Terms of Use as set out on this page before using this online space. These terms govern your use of the nelson.social online space and by using the nelson.social online space, you agree to be bound by these terms.')
}
}
}
const rewriter = new HTMLRewriter().on('p', new AboutRewriter());
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});