Skip to content

Commit

Permalink
[Fixes GeoNode#42] Dynamicully set CORS ALLOW ORIGINS
Browse files Browse the repository at this point in the history
  • Loading branch information
t-book committed May 20, 2024
1 parent 62a0d29 commit bd662e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docker/nginx/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ export GEONODE_LB_PORT=${GEONODE_LB_PORT:-8000}
export GEOSERVER_LB_HOST_IP=${GEOSERVER_LB_HOST_IP:-geoserver}
export GEOSERVER_LB_PORT=${GEOSERVER_LB_PORT:-8080}

# Set Access-Control-Allow-Origin based on CORS_ALLOW_ALL_ORIGINS
if [ "$(echo ${CORS_ALLOW_ALL_ORIGINS} | tr '[:upper:]' '[:lower:]')" = "true" ]; then
export NGINX_ALLOW_ORIGIN="*"
else
NGINX_ALLOW_ORIGIN=$(echo "${SITEURL}" | sed -e 's|^https\?://||' -e 's|/$||')
export NGINX_ALLOW_ORIGIN
fi

defined_envs=$(printf '${%s} ' $(env | cut -d= -f1))

echo "Replacing environment variables"
Expand Down
1 change: 1 addition & 0 deletions docker/nginx/geonode.conf.envsubst
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ location / {
add_header Content-Length 0;
add_header Content-Type text/plain;
add_header Access-Control-Max-Age 1728000;
add_header Access-Control-Allow-Origin "$NGINX_ALLOW_ORIGIN";
return 200;
}

Expand Down

0 comments on commit bd662e1

Please sign in to comment.