From 1d6b11b0b26dbdbed4b4e8f8d3e233e971ceb0a9 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Thu, 11 Dec 2025 14:54:16 -0800 Subject: [PATCH 1/2] Assets example: Serve index.html from assets directory --- 06-assets/assets/index.html | 15 +++++++++++++++ 06-assets/src/worker.py | 23 ----------------------- tests/test_examples.py | 2 +- 3 files changed, 16 insertions(+), 24 deletions(-) create mode 100644 06-assets/assets/index.html diff --git a/06-assets/assets/index.html b/06-assets/assets/index.html new file mode 100644 index 0000000..28c8170 --- /dev/null +++ b/06-assets/assets/index.html @@ -0,0 +1,15 @@ + + + + Assets Example + + + +
+

Assets Handling Example

+

This demonstrates serving static content from a Python Worker.

+ Example circle image +
+ + + diff --git a/06-assets/src/worker.py b/06-assets/src/worker.py index fd15f5a..8cf08f3 100644 --- a/06-assets/src/worker.py +++ b/06-assets/src/worker.py @@ -1,30 +1,7 @@ from workers import WorkerEntrypoint, Response from urllib.parse import urlparse -INDEX_PAGE = """ - - - - Assets Example - - - -
-

Assets Handling Example

-

This demonstrates serving static content from a Python Worker.

- Example circle image -
- - - -""" - - 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) diff --git a/tests/test_examples.py b/tests/test_examples.py index 700c127..163c8ca 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -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"), From c9c703f5cc2753b7a2caa8e320cb03b7f2c51a32 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 11 Dec 2025 23:22:47 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- 06-assets/src/worker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/06-assets/src/worker.py b/06-assets/src/worker.py index 8cf08f3..a3d4533 100644 --- a/06-assets/src/worker.py +++ b/06-assets/src/worker.py @@ -1,5 +1,5 @@ -from workers import WorkerEntrypoint, Response -from urllib.parse import urlparse +from workers import WorkerEntrypoint + class Default(WorkerEntrypoint): async def fetch(self, request):