Skip to content

Commit 6799351

Browse files
committed
Use middleware
Signed-off-by: Anuraag Agrawal <[email protected]>
1 parent 3e5015b commit 6799351

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

docs/deployment.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use a Python application server to run a service.
66
## Application Servers
77

88
Connect services are standard ASGI or WSGI applications that can be run with an off-the-shelf Python
9-
application server. This means generally, any experience in running a Python application can be applied
10-
to running Connect as-is.
9+
application server. Generally, any experience in running a Python application can be applied to running
10+
Connect as-is.
1111

1212
### HTTP/1.1
1313

@@ -41,18 +41,28 @@ When in doubt, if you do not use bidirectional streaming, we recommend one of th
4141
Connect services are standard ASGI and WSGI applications so any CORS middleware can be used to
4242
enable it.
4343

44-
For example, with an ASGI application using Starlette:
44+
For example, with an ASGI application using the [asgi-cors](https://pypi.org/project/asgi-cors/)
45+
middleware:
4546

4647
```python
47-
from starlette.middleware.cors import CORSMiddleware
48-
from starlette.applications import Starlette
49-
50-
app = Starlette()
51-
app.add_middleware(
52-
CORSMiddleware,
53-
allow_origins=["*"],
54-
allow_methods=["GET", "POST"],
55-
allow_headers=["*"],
48+
from asgi_cors import asgi_cors
49+
50+
from greet.v1.greet_connect import GreetServiceASGIApplication
51+
from server import Greeter
52+
53+
app = GreetServiceASGIApplication(Greeter())
54+
55+
# app is a standard ASGI application - any middleware works as-is
56+
app = asgi_cors(
57+
app,
58+
hosts=["https://acme.com"],
59+
# POST is used for all APIs except for idempotent unary RPCs that may support GET
60+
methods=["GET", "POST"],
61+
headers=[
62+
"content-type",
63+
"connect-protocol-version",
64+
"connect-timeout-ms",
65+
"x-user-agent",
66+
],
5667
)
57-
# Mount your Connect application
5868
```

0 commit comments

Comments
 (0)