-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_mount.py
More file actions
28 lines (23 loc) · 867 Bytes
/
Copy pathapi_mount.py
File metadata and controls
28 lines (23 loc) · 867 Bytes
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
"""
Mount Django API within the FastHTML/Starlette application.
This allows the Django REST API to be accessible through the main app server.
"""
import os
from django.core.asgi import get_asgi_application
# Ensure Django settings are configured
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_config.settings')
# Get Django ASGI application
django_app = get_asgi_application()
async def django_api_middleware(scope, receive, send):
"""
Middleware to route /api/* requests to Django.
All other requests pass through to FastHTML.
"""
path = scope.get('path', '')
# Route API requests to Django
if path.startswith('/api/') or path.startswith('/admin/'):
await django_app(scope, receive, send)
else:
# This will be handled by FastHTML
# We shouldn't reach here if properly integrated
pass