40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
"""
|
|
ASGI config for hospital_management project.
|
|
|
|
It exposes the ASGI callable as a module-level variable named ``application``.
|
|
|
|
For more information on this file, see
|
|
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
|
|
"""
|
|
|
|
import os
|
|
from django.core.asgi import get_asgi_application
|
|
|
|
# Set Django settings module
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hospital_management.settings')
|
|
|
|
# Initialize Django ASGI application early to ensure AppRegistry is populated
|
|
# before importing code that may import ORM models.
|
|
django_asgi_app = get_asgi_application()
|
|
|
|
# Import Channels components after Django initialization
|
|
from channels.routing import ProtocolTypeRouter, URLRouter
|
|
from channels.auth import AuthMiddlewareStack
|
|
from channels.security.websocket import AllowedHostsOriginValidator
|
|
|
|
# Import WebSocket routing
|
|
from hospital_management.routing import websocket_urlpatterns
|
|
|
|
# Configure ASGI application
|
|
application = ProtocolTypeRouter({
|
|
# Django's ASGI application to handle traditional HTTP requests
|
|
"http": django_asgi_app,
|
|
|
|
# WebSocket handler with authentication and origin validation
|
|
"websocket": AllowedHostsOriginValidator(
|
|
AuthMiddlewareStack(
|
|
URLRouter(websocket_urlpatterns)
|
|
)
|
|
),
|
|
})
|