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
// This val uses Hono, a lightweight web framework, to create a simple HTML page.
// It demonstrates how to use Hono's HTML templating and routing capabilities.
// Side note: This code is generated using Townie AI.
import { Hono } from "https://esm.sh/hono";
import { html } from "https://esm.sh/hono/html";
const app = new Hono();
app.get("/", (c) => {
const name = "World";
return c.html(
html`
<!DOCTYPE html>
<html>
<head>
<title>Hello from Hono</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
}
.container {
text-align: center;
padding: 20px;
background-color: white;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
h1 {
color: #333;
}
p {
color: #666;
}
.source-link {
margin-top: 20px;
font-size: 0.8em;
}
</style>
</head>
<body>
<div class="container">
<h1>Hello, ${name}!</h1>
<p>This page is rendered using Hono.</p>
<p class="source-link">
<a href="${import.meta.url.replace("esm.town", "val.town")}" target="_blank">View Source</a>
</p>
</div>
</body>
</html>
`,
);
});
export default async function server(req: Request): Promise<Response> {
return app.fetch(req);
}