root: add lifespan shim to prevent errors
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
956922820b
commit
e831e4fb94
|
@ -20,11 +20,34 @@ django.setup()
|
|||
# pylint: disable=wrong-import-position
|
||||
from authentik.root import websocket # noqa # isort:skip
|
||||
|
||||
|
||||
class LifespanApp:
|
||||
"""
|
||||
temporary shim for https://github.com/django/channels/issues/1216
|
||||
needed so that hypercorn doesn't display an error.
|
||||
this uses ASGI 2.0 format, not the newer 3.0 single callable
|
||||
"""
|
||||
|
||||
def __init__(self, scope):
|
||||
self.scope = scope
|
||||
|
||||
async def __call__(self, receive, send):
|
||||
if self.scope["type"] == "lifespan":
|
||||
while True:
|
||||
message = await receive()
|
||||
if message["type"] == "lifespan.startup":
|
||||
await send({"type": "lifespan.startup.complete"})
|
||||
elif message["type"] == "lifespan.shutdown":
|
||||
await send({"type": "lifespan.shutdown.complete"})
|
||||
return
|
||||
|
||||
|
||||
application = SentryAsgiMiddleware(
|
||||
ProtocolTypeRouter(
|
||||
{
|
||||
"http": get_asgi_application(),
|
||||
"websocket": URLRouter(websocket.websocket_urlpatterns),
|
||||
"lifespan": LifespanApp,
|
||||
}
|
||||
)
|
||||
)
|
||||
|
|
Reference in New Issue