Skip to content

Commit 2bb1b26

Browse files
committed
set CORS headers based on dev vs prod; add helper make targets for dev
1 parent 42bd840 commit 2bb1b26

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

Makefile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: deploy deploy-staging sync-on-prod fetch-nginx-config
1+
.PHONY: deploy deploy-staging sync-on-prod fetch-nginx-config clipping-service
22

33
GIT_DIR := /opt/ckan-catalog/data.naturalcapitalproject.stanford.edu
44
CKAN_PROD_URL := https://data.naturalcapitalproject.stanford.edu
@@ -24,3 +24,18 @@ fetch-nginx-config:
2424
gcloud compute scp $(GCLOUD_COMMON_ARGS) $(PROD_VM_NAME):/etc/nginx/sites-enabled/ckan host-nginx/etc.nginx.sites-available.ckan
2525
gcloud compute scp $(GCLOUD_COMMON_ARGS) $(PROD_VM_NAME):/etc/nginx/nginx.conf host-nginx/etc.nginx.nginx.conf
2626
gcloud compute scp $(GCLOUD_COMMON_ARGS) $(PROD_VM_NAME):/etc/nginx/throttle-bots.conf host-nginx/etc.nginx.throttle-bots.conf
27+
28+
29+
# Targets for local development:
30+
CLIP_ENV := clipenv
31+
32+
env-clip:
33+
conda create -n $(CLIP_ENV) -y -c conda-forge python=3.12
34+
conda env update -n $(CLIP_ENV) --file ./clipping-service/app/requirements.txt
35+
conda env config vars set -n $(CLIP_ENV) DEV_MODE=True
36+
@echo "To activate the environment and run the clipping service:"
37+
@echo ">> conda activate $(CLIP_ENV)"
38+
@echo ">> make clipping-service"
39+
40+
clipping-service:
41+
python -m gunicorn --chdir ./clipping-service/app app:app --reload

clipping-service/app/app.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,22 @@
2424
from osgeo import osr
2525

2626
app = flask.Flask(__name__, template_folder='templates')
27+
28+
cors_origins = [
29+
'https://data-staging.naturalcapitalproject.org',
30+
'https://data.naturalcapitalproject.stanford.edu'
31+
]
32+
33+
if os.environ.get("DEV_MODE"):
34+
cors_origins.append("https://localhost:*")
35+
2736
CORS(app, resources={
2837
'/*': {
29-
'origins': [
30-
# Only use localhost for local development.
31-
# 'http://localhost:*',
32-
# 'https://localhost:*',
33-
# 'http://127.0.0.1:*',
34-
'https://data-staging.naturalcapitalproject.org',
35-
'https://data.naturalcapitalproject.stanford.edu',
36-
]
38+
'origins': cors_origins
3739
}
3840
})
39-
logging.basicConfig(level=logging.DEBUG)
4041

42+
logging.basicConfig(level=logging.DEBUG)
4143

4244
# PLAN: write a logging handler to listen for progress messages and send those
4345
# to the client.

0 commit comments

Comments
 (0)