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..a3d4533 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 -
- - - -""" +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) 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"),