ASGI Django Application Hosting in Windows Server 2012

Viewed 25

Can I host ASGI Django App in Windows Server 2012 backed with Apache? I explored several blogs which mentions about "mod_wsgi" which confused me if it could handle ASGI application.

Can this server handle websocket requests?

Medium/Analytics-Vidya

Prof. Dr. Christian Leubner

settings.py

INSTALLED_APPS = [
    'channels',
    'rest_framework',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'broadcast',
]

ASGI_APPLICATION = 'AppMain.asgi.application'

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels_redis.core.RedisChannelLayer",
        "CONFIG": {
            "hosts": [("localhost", 6379)],
            # "hosts":[os.environ.get('REDIS_URL', 'redis://localhost:6379')]
        },
    },
}

asgi.py

import os

import django
from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.auth import AuthMiddlewareStack
from django.urls import path
from broadcast.consumers import AConsumer
import broadcast.routing

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'AppMain.settings')
django.setup()

# application = get_asgi_application()
application = ProtocolTypeRouter({
    'http' : get_asgi_application(),
    'websocket' : AuthMiddlewareStack(
        URLRouter(
            broadcast.routing.websocket_urlpatterns
        )
    )
})
0 Answers
Related