mirror of
https://github.com/wassname/ray.git
synced 2026-07-26 13:37:24 +08:00
[Serve] Produtionize Starlette Middlewares (#10529)
This commit is contained in:
@@ -316,3 +316,31 @@ To call a method via Python, do the following:
|
||||
|
||||
handle = serve.get_handle("backend_name")
|
||||
handle.options(method_name="other_method").remote(5)
|
||||
|
||||
How do I enable CORS and other HTTP features?
|
||||
---------------------------------------------
|
||||
|
||||
Serve supports arbitrary `Starlette middlewares <https://www.starlette.io/middleware/>`_
|
||||
and custom middlewares in Starlette format. The example below shows how to enable
|
||||
`Cross-Origin Resource Sharing (CORS) <https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS>`_.
|
||||
You can follow the same pattern for other Starlette middlewares.
|
||||
|
||||
.. note::
|
||||
|
||||
Serve does not list ``Starlette`` as one of its dependencies. To utilize this feature,
|
||||
you will need to:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
pip install starlette
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from starlette.middleware import Middleware
|
||||
from starlette.middleware.cors import CORSMiddleware
|
||||
|
||||
serve.init(
|
||||
http_middlewares=[
|
||||
Middleware(
|
||||
CORSMiddleware, allow_origins=["*"], allow_methods=["*"])
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user