Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update CORS documentation #764

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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