-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.py
More file actions
44 lines (29 loc) · 1.35 KB
/
worker.py
File metadata and controls
44 lines (29 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# SPDX-FileCopyrightText: 2025 icalendar-anonymizer contributors
# SPDX-License-Identifier: AGPL-3.0-or-later
"""Cloudflare Workers entry point for iCalendar anonymizer web service.
This module provides the Worker entry point that integrates the FastAPI application
with Cloudflare Workers runtime using Pyodide (Python WebAssembly).
This file must be at the root level so that python_modules/ is in the import path.
"""
import os
from workers import WorkerEntrypoint
# Set environment marker before importing app to disable static file mounting
# In Cloudflare Workers, static files are served via Assets, not FastAPI
os.environ["CLOUDFLARE_WORKERS"] = "true"
from icalendar_anonymizer.webapp.main import app
class Default(WorkerEntrypoint):
"""Default Worker entry point for Cloudflare Workers.
Handles incoming HTTP requests and routes them to the FastAPI application.
"""
async def fetch(self, request):
"""Handle incoming HTTP request.
Args:
request: Cloudflare Workers Request object
Returns:
Cloudflare Workers Response object
"""
import asgi
# Copy secrets from Workers env to os.environ for app compatibility
if hasattr(self.env, "FERNET_KEY"):
os.environ["FERNET_KEY"] = self.env.FERNET_KEY
return await asgi.fetch(app, request, self.env)