Skip to content

Commit 97e0439

Browse files
robintwlossyrob
andauthored
Added tips and tricks document to the docs folder (#277)
Co-authored-by: Rob Emanuele <[email protected]>
1 parent 00f5ca3 commit 97e0439

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/tips-and-tricks.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Tips and Tricks
2+
This page contains a few 'tips and tricks' for getting stac-fastapi working in various situations.
3+
4+
## Get stac-fastapi working with CORS
5+
CORS (Cross-Origin Resource Sharing) support may be required to use stac-fastapi in certain situations. For example, if you are running
6+
[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.
7+
8+
To do this, edit `stac_fastapi/sqlalchemy/stac_fastapi/sqlalchemy/app.py` (or the equivalent in the `pgstac` folder) and add the following import:
9+
10+
```
11+
from fastapi.middleware.cors import CORSMiddleware
12+
```
13+
14+
and then edit the `api = StacApi(...` call to add the following parameter:
15+
16+
```
17+
middlewares=[lambda app: CORSMiddleware(app, allow_origins=["*"])]
18+
```
19+
20+
If needed, you can edit the `allow_origins` parameter to only allow CORS requests from specific origins.
21+
22+
## Enable the Context extension
23+
The Context STAC extension provides information on the number of items matched and returned from a STAC search. This is required by various other STAC-related tools, such as the pystac command-line client. To enable the extension, edit `stac_fastapi/sqlalchemy/stac_fastapi/sqlalchemy/app.py` (or the equivalent in the `pgstac` folder) and add the following import:
24+
25+
```
26+
from stac_fastapi.extensions.core.context import ContextExtension
27+
```
28+
29+
and then edit the `api = StacApi(...` call to add `ContextExtension()` to the list given as the `extensions` parameter.

0 commit comments

Comments
 (0)