Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions 06-assets/assets/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>Assets Example</title>
<link rel="stylesheet" href="/style.css">
</head>
<body>
<div class="container">
<h1>Assets Handling Example</h1>
<p>This demonstrates serving static content from a Python Worker.</p>
<img src="/image.svg" alt="Example circle image" />
</div>
<script src="/script.js"></script>
</body>
</html>
25 changes: 1 addition & 24 deletions 06-assets/src/worker.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,7 @@
from workers import WorkerEntrypoint, Response
from urllib.parse import urlparse

INDEX_PAGE = """
<!DOCTYPE html>
<html>
<head>
<title>Assets Example</title>
<link rel="stylesheet" href="/style.css">
</head>
<body>
<div class="container">
<h1>Assets Handling Example</h1>
<p>This demonstrates serving static content from a Python Worker.</p>
<img src="/image.svg" alt="Example circle image" />
</div>
<script src="/script.js"></script>
</body>
</html>
"""
from workers import WorkerEntrypoint


class Default(WorkerEntrypoint):
async def fetch(self, request):
# Example of serving static assets
path = urlparse(request.url).path
if path in ["/", "/index.html"]:
return Response(INDEX_PAGE, headers={"Content-Type": "text/html"})

return await self.env.ASSETS.fetch(request)
2 changes: 1 addition & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_05_langchain(dev_server):
def test_06_assets(dev_server):
port = dev_server
pairs = [
("", "text/html"),
("", "text/html; charset=utf-8"),
("image.svg", "image/svg+xml"),
("style.css", "text/css; charset=utf-8"),
("script.js", "text/javascript; charset=utf-8"),
Expand Down
Loading