I want to deploy ComfyUI on a service platform implemented with fastapi and expose ComfyUI’s front-end routes to the service platform. However, since ComfyUI is implemented with aiohttp, I want to know how to mount aiohttp’s routes to fastapi and access them normally.
I have tried to use a2wsgi.WSGIMiddleware to convert aiohttp app to ASGI and then mount to fastapi, but there are some bugs such as
uvicorn.error - ERROR - Exception in ASGI application
Traceback (most recent call last):
File "/home/admin/.local/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 399, in run_asgi
result = await app( # type: ignore[func-returns-value]
File "/home/admin/.local/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__
return await self.app(scope, receive, send)
File "/home/admin/.local/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in __call__
await super().__call__(scope, receive, send)
File "/home/admin/.local/lib/python3.10/site-packages/starlette/applications.py", line 123, in __call__
await self.middleware_stack(scope, receive, send)
File "/home/admin/.local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 186, in __call__
raise exc
File "/home/admin/.local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 164, in __call__
await self.app(scope, receive, _send)
File "/home/admin/.local/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "/home/admin/.local/lib/python3.10/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
raise exc
File "/home/admin/.local/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "/home/admin/.local/lib/python3.10/site-packages/starlette/routing.py", line 756, in __call__
await self.middleware_stack(scope, receive, send)
File "/home/admin/.local/lib/python3.10/site-packages/starlette/routing.py", line 776, in app
await route.handle(scope, receive, send)
File "/home/admin/.local/lib/python3.10/site-packages/starlette/routing.py", line 485, in handle
await self.app(scope, receive, send)
File "/home/admin/.local/lib/python3.10/site-packages/a2wsgi/wsgi.py", line 165, in __call__
return await responder(scope, receive, send)
File "/home/admin/.local/lib/python3.10/site-packages/a2wsgi/wsgi.py", line 200, in __call__
await self.loop.run_in_executor(
File "/opt/miniconda3/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/admin/.local/lib/python3.10/site-packages/a2wsgi/wsgi.py", line 256, in wsgi
iterable = self.app(environ, start_response)
TypeError: Application.__call__() takes 1 positional argument but 3 were given
It’s the first time I write web code, and never used fastapi or aiohttp before, so this may be an available way, but I don’t write correctly.
I hope someone can help me or give me some suggestions.