File tree Expand file tree Collapse file tree 3 files changed +16
-24
lines changed
Expand file tree Collapse file tree 3 files changed +16
-24
lines changed Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 11from workers import WorkerEntrypoint , Response
22from 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-
234class 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 )
Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ def test_05_langchain(dev_server):
7979def 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" ),
You can’t perform that action at this time.
0 commit comments