Skip to content

Commit 4491fa1

Browse files
update CORS documentation (#764)
1 parent 8235d91 commit 4491fa1

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

docs/src/tips-and-tricks.md

+13-12
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22

33
This page contains a few 'tips and tricks' for getting **stac-fastapi** working in various situations.
44

5-
## Get stac-fastapi working with CORS
5+
## Application Middlewares
66

7-
CORS (Cross-Origin Resource Sharing) support may be required to use stac-fastapi in certain situations.
8-
For example, if you are running [stac-browser](https://github.com/radiantearth/stac-browser) to browse the STAC catalog created by **stac-fastapi**, then you will need to enable CORS support.
9-
To do this, edit your backend's `app.py` and add the following import:
7+
By default the `StacApi` class will enable 3 Middlewares (`BrotliMiddleware`, `CORSMiddleware` and `ProxyHeaderMiddleware`). You may want to overwrite the defaults configuration by editing your backend's `app.py`:
108

119
```python
12-
from fastapi.middleware.cors import CORSMiddleware
13-
```
14-
15-
and then edit the `api = StacApi(...` call to add the following parameter:
10+
from starlette.middleware import Middleware
1611

17-
```python
18-
middlewares=[lambda app: CORSMiddleware(app, allow_origins=["*"])]
12+
from stac_fastapi.api.app import StacApi
13+
from stac_fastapi.api.middleware import CORSMiddleware
14+
15+
api = StacApi(
16+
...
17+
middlewares=[
18+
Middleware(CORSMiddleware, allow_origins=["https://myendpoints.io"])
19+
],
20+
...
21+
)
1922
```
2023

21-
If needed, you can edit the `allow_origins` parameter to only allow CORS requests from specific origins.
22-
2324
## Set API title, description and version
2425

2526
For the landing page, you can set the API title, description and version using environment variables.

0 commit comments

Comments
 (0)