From c37648f79fd015a3352b36ac6f631df56afd51f9 Mon Sep 17 00:00:00 2001 From: Robin Wilson Date: Mon, 11 Oct 2021 12:35:29 +0100 Subject: [PATCH] Added tips and tricks document to the docs folder --- docs/tips-and-tricks.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 docs/tips-and-tricks.md diff --git a/docs/tips-and-tricks.md b/docs/tips-and-tricks.md new file mode 100644 index 000000000..3d4c9ac0f --- /dev/null +++ b/docs/tips-and-tricks.md @@ -0,0 +1,29 @@ +# Tips and Tricks +This page contains a few 'tips and tricks' for getting stac-fastapi working in various situations. + +## Get stac-fastapi working with CORS +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 `stac_fastapi/sqlalchemy/stac_fastapi/sqlalchemy/app.py` (or the equivalent in the `pgstac` folder) and add the following import: + +``` +from fastapi.middleware.cors import CORSMiddleware +``` + +and then edit the `api = StacApi(...` call to add the following parameter: + +``` +middlewares=[lambda app: CORSMiddleware(app, allow_origins=["*"])] +``` + +If needed, you can edit the `allow_origins` parameter to only allow CORS requests from specific origins. + +## Enable the Context extension +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: + +``` +from stac_fastapi.extensions.core.context import ContextExtension +``` + +and then edit the `api = StacApi(...` call to add `ContextExtension()` to the list given as the `extensions` parameter. \ No newline at end of file