This repository has been archived by the owner on Aug 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edgeside-rendered-website.js
78 lines (69 loc) · 1.58 KB
/
edgeside-rendered-website.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* Worker logic
* Renders a complete website on the edge
* Any assets need to be stored in some other location, and pointed to with absolute URLs
*
* @async
* @function
* @param {Request} request - The incoming request data
* @returns {Response} - Returns markup and headers
*/
async function handleRequest(request) {
const DATA = {
headers: {
...request.headers,
"Content-Type": "text/html;charset=UTF-8"
}
};
return new Response(bodyMarkup, DATA);
}
addEventListener("fetch", event => {
return event.respondWith(handleRequest(event.request));
});
/**********************/
/* Inline styles */
/**********************/
const STYLES = `
<style>
* {
font-smooth: always;
-webkit-font-smoothing: antialiased;
box-sizing: border-box;
}
html {
padding: 0;
margin: 0;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
font-size: 16px;
padding: 0;
margin: 0;
}
</style>
`;
/**********************/
/* Markup */
/**********************/
const MAIN_CONTENT = `
<h1>Edge-side rendered website</h1>
`;
const bodyMarkup = `
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Edge-side rendered website</title>
${STYLES}
</head>
<body>
<main>
<article>
${MAIN_CONTENT}
<!-- Note the absolute URL to the image; assets should reside elsewhere and be pointed to with absolute URLs -->
<img src="https://images.theconversation.com/files/280024/original/file-20190618-118505-aag3r7.jpg">
</article>
</main>
</body>
</html>
`;