Skip to content

Commit

Permalink
update CORS documentation (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago authored Oct 17, 2024
1 parent 8235d91 commit 4491fa1
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions docs/src/tips-and-tricks.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@

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

## Get stac-fastapi working with CORS
## Application Middlewares

CORS (Cross-Origin Resource Sharing) support may be required to use stac-fastapi in certain situations.
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.
To do this, edit your backend's `app.py` and add the following import:
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`:

```python
from fastapi.middleware.cors import CORSMiddleware
```

and then edit the `api = StacApi(...` call to add the following parameter:
from starlette.middleware import Middleware

```python
middlewares=[lambda app: CORSMiddleware(app, allow_origins=["*"])]
from stac_fastapi.api.app import StacApi
from stac_fastapi.api.middleware import CORSMiddleware

api = StacApi(
...
middlewares=[
Middleware(CORSMiddleware, allow_origins=["https://myendpoints.io"])
],
...
)
```

If needed, you can edit the `allow_origins` parameter to only allow CORS requests from specific origins.

## Set API title, description and version

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

0 comments on commit 4491fa1

Please sign in to comment.