Skip to content

Commit bbfcb03

Browse files
committed
initial commit
0 parents  commit bbfcb03

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fastapi

src/worker.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import jinja2
2+
from fastapi import FastAPI, Request
3+
4+
environment = jinja2.Environment()
5+
template = environment.from_string("Hello, {{ name }}!")
6+
7+
8+
async def on_fetch(request, env):
9+
import asgi
10+
11+
return await asgi.fetch(app, request, env)
12+
13+
14+
app = FastAPI()
15+
16+
17+
@app.get("/")
18+
async def root():
19+
message = "This is an example of FastAPI with Jinja2 - go to /hi/<name> to see a template rendered"
20+
return {"message": message}
21+
22+
23+
@app.get("/hi/{name}")
24+
async def say_hi(name: str):
25+
message = template.render(name=name)
26+
return {"message": message}
27+
28+
29+
@app.get("/env")
30+
async def env(req: Request):
31+
env = req.scope["env"]
32+
return {
33+
"message": "Here is an example of getting an environment variable: "
34+
+ env.MESSAGE
35+
}

vendor.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
markupsafe
2+
jinja2

wrangler.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name = "fastapi-worker"
2+
main = "src/worker.py"
3+
compatibility_flags = ["python_workers"]
4+
compatibility_date = "2025-03-16"
5+
6+
[vars]
7+
MESSAGE = "My env var"
8+
9+
[[rules]]
10+
globs = ["vendor/**"]
11+
type = "Data"
12+
fallthrough = true

0 commit comments

Comments
 (0)