Middleware to Dispatch to multiple ASGI applications, extracted from hypercorn.
Project description
asgi-dispatcher-middleware
Middleware to Dispatch to multiple ASGI applications, extracted from hypercorn.
Dispatch to multiple ASGI applications
It is often useful serve multiple ASGI applications at once, under differing root paths. This middleware allows multiple applications to be served on different mounts.
The DispatcherMiddleware
takes a dictionary of applications keyed by the root path.
The order of entry in this dictionary is important, as the root paths will be checked in
this order. Hence it is important to add /a/b
before /a
or the latter will match
everything first. Also note that the root path should not include the trailing slash.
An example usage is to to serve a graphql application alongside a static file serving
application. Using the graphql app is called graphql_app
serving everything with the
root path /graphql
and a static file app called static_app
serving everything else
i.e. a root path of /
the DispatcherMiddleware
can be setup as,
from asgi_dispatcher_middleware import DispatcherMiddleware
dispatcher_app = DispatcherMiddleware({
"/graphql": graphql_app,
"/": static_app,
})
which can then be served by any asgi framework,
$ hypercorn module:dispatcher_app
$ uvicorn module:dispatcher_app
See also
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for asgi-dispatcher-middleware-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 765048e09351fc0e3dface205ff0b4358e063f1b0c09ce50c5080e8d0f1560d8 |
|
MD5 | 69520f41bfa162eb231df1067f78cbb6 |
|
BLAKE2b-256 | 125d84dbcece5ad2fd0d61581e528530b6f7e82364a5f88dc3bff8299cf52bdf |
Hashes for asgi_dispatcher_middleware-1.0.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 635a89e327912e951afedec20cbb493a6c3ba27fcf1b2bb5bc6ae72a8bf1fda4 |
|
MD5 | f26fb7243f38f95dce02f314a431d3d7 |
|
BLAKE2b-256 | 4075bfc08fc185e49d57f3b9b1979fe8b944d484743869c07afb27310e310c09 |