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
/**
* Hacker News Clone (HTML frontend)
* This script sets up an HTTP Val to serve a simple HTML page that mimics Hacker News.
* The page contains static, fake example stories for now.
*/
export default async function(req: Request): Promise<Response> {
const htmlContent = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hacker News Clone</title>
<style>
body {
font-family: Arial, sans-serif;
}
.container {
width: 80%;
margin: 0 auto;
}
.story {
border-bottom: 1px solid #ddd;
padding: 10px 0;
}
.title {
font-size: 1.2em;
margin: 0;
}
.meta {
color: #555;
}
</style>
</head>
<body>
<div class="container">
<h1>Hacker News Clone</h1>
<div class="story">
<p class="title"><a href="#">Fake Story 1</a></p>
<p class="meta">100 points by user1 | 10 comments</p>
</div>
<div class="story">
<p class="title"><a href="#">Fake Story 2</a></p>
<p class="meta">80 points by user2 | 8 comments</p>
</div>
<div class="story">
<p class="title"><a href="#">Fake Story 3</a></p>
<p class="meta">60 points by user3 | 6 comments</p>
</div>
</div>
</body>
</html>
`;
return new Response(htmlContent, {
headers: {
'Content-Type': 'text/html',
},
});
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
July 17, 2024