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
File details
Details for the file asgi-dispatcher-middleware-1.0.0.tar.gz
.
File metadata
- Download URL: asgi-dispatcher-middleware-1.0.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 765048e09351fc0e3dface205ff0b4358e063f1b0c09ce50c5080e8d0f1560d8 |
|
MD5 | 69520f41bfa162eb231df1067f78cbb6 |
|
BLAKE2b-256 | 125d84dbcece5ad2fd0d61581e528530b6f7e82364a5f88dc3bff8299cf52bdf |
File details
Details for the file asgi_dispatcher_middleware-1.0.0-py2.py3-none-any.whl
.
File metadata
- Download URL: asgi_dispatcher_middleware-1.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 635a89e327912e951afedec20cbb493a6c3ba27fcf1b2bb5bc6ae72a8bf1fda4 |
|
MD5 | f26fb7243f38f95dce02f314a431d3d7 |
|
BLAKE2b-256 | 4075bfc08fc185e49d57f3b9b1979fe8b944d484743869c07afb27310e310c09 |