Skip to content

Commit 1d6b11b

Browse files
committed
Assets example: Serve index.html from assets directory
1 parent c074858 commit 1d6b11b

File tree

3 files changed

+16
-24
lines changed

3 files changed

+16
-24
lines changed

06-assets/assets/index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Assets Example</title>
5+
<link rel="stylesheet" href="/style.css">
6+
</head>
7+
<body>
8+
<div class="container">
9+
<h1>Assets Handling Example</h1>
10+
<p>This demonstrates serving static content from a Python Worker.</p>
11+
<img src="/image.svg" alt="Example circle image" />
12+
</div>
13+
<script src="/script.js"></script>
14+
</body>
15+
</html>

06-assets/src/worker.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,7 @@
11
from workers import WorkerEntrypoint, Response
22
from urllib.parse import urlparse
33

4-
INDEX_PAGE = """
5-
<!DOCTYPE html>
6-
<html>
7-
<head>
8-
<title>Assets Example</title>
9-
<link rel="stylesheet" href="/style.css">
10-
</head>
11-
<body>
12-
<div class="container">
13-
<h1>Assets Handling Example</h1>
14-
<p>This demonstrates serving static content from a Python Worker.</p>
15-
<img src="/image.svg" alt="Example circle image" />
16-
</div>
17-
<script src="/script.js"></script>
18-
</body>
19-
</html>
20-
"""
21-
22-
234
class Default(WorkerEntrypoint):
245
async def fetch(self, request):
256
# Example of serving static assets
26-
path = urlparse(request.url).path
27-
if path in ["/", "/index.html"]:
28-
return Response(INDEX_PAGE, headers={"Content-Type": "text/html"})
29-
307
return await self.env.ASSETS.fetch(request)

tests/test_examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_05_langchain(dev_server):
7979
def test_06_assets(dev_server):
8080
port = dev_server
8181
pairs = [
82-
("", "text/html"),
82+
("", "text/html; charset=utf-8"),
8383
("image.svg", "image/svg+xml"),
8484
("style.css", "text/css; charset=utf-8"),
8585
("script.js", "text/javascript; charset=utf-8"),

0 commit comments

Comments
 (0)