-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (37 loc) · 1.18 KB
/
index.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
33
34
35
36
37
38
39
40
41
async function handleRequest(request) {
const { pathname, searchParams } = new URL(request.url)
if (pathname === '/oembed') {
return new Response(JSON.stringify({
type: "photo",
author_name: searchParams.get('author')
}), {
headers: {
'content-type': 'application/json'
},
});
}
const title = searchParams.get('title');
const author = searchParams.get('author');
const color = searchParams.get('color');
return new Response(
`<!DOCTYPE html>
<html prefix="og: http://ogp.me/ns#">
<head>
${title ? `<meta property="og:title" content="${title}">` : ''}
<meta property="theme-color" content="#${color}">
<meta content="https://img.rauf.wtf/1x1_original_fdhufkgdyfgsdjfs.png" property="og:image">
${author ? `<link type="application/json+oembed" href="https://embed.almeidx.workers.dev/oembed?author=${author}">` : ''}
</head>
<body>
<h1>Hello World</h1>
<p>This worker was made by <a href="https://github.com/almeidx">Almeida</a>.</p>
</body>
</html>`, {
headers: {
'content-type': 'text/html;charset=UTF-8',
},
});
}
addEventListener("fetch", event => {
return event.respondWith(handleRequest(event.request));
});