I'm trying to run FastAPI and wsgidav through a single hypercorn server.
According to the documentation it should work like this:
import hypercorn
import asyncio
from hypercorn.config import Config
from hypercorn.asyncio import serve
from hypercorn.middleware import DispatcherMiddleware, AsyncioWSGIMiddleware
from fastapi import FastAPI
from wsgidav import WsgiDavApp
def run(hypercorn_cfg):
fastapi_app = FastAPI()
// ...
fastapi_app.mount("/", StaticFiles(directory=".../web/", html=True), name="public")
dav_app = hypercorn.AsyncioWSGIMiddleware( WsgiDavApp({ ... }) )
dispatcher = DispatcherMiddleware({
'/dav': dav_app,
'/': fastapi_app
})
asyncio.run(serve(dispatcher, hypercorn_cfg))
The config for dav_app looks like this:
dav_cfg = {
'host': '0.0.0.0',
'port': 8000,
'provider_mapping': {
'/dav/': '/path/to/files'
},
"simple_dc": {
"user_mapping": {
"*": True
}
},
"verbose": 3,
}
Running either my webdav app or my fastAPI app in hypercorn works fine. My webdav app works fine both with and without the AsyncioWSGIMiddleware wrapper. However, putting webdav app into the dispatcher and running hypercorn on the dispatcher does not work at all. Instead, Hypercorn ends the startup process with a LifespanTimoutError:
hypercorn.utils.LifespanTimeoutError: Timeout whilst awaiting startup. \
Your application may not support the ASGI Lifespan protocol correctly, \
alternatively the startup_timeout configuration is incorrect.
FastAPI alone runs well in a dispatcher like this. For some reason I have to map it to empty string instead of '/', though.
dispatcher = DispatcherMiddleware({
'': app
})
What am I missing? Shouldn't the WSGI Middleware take care of the lifespan protocol? Is there a bug in wsgidav?