From 451f335bc599e1f7c136d15b241905808c5084ab Mon Sep 17 00:00:00 2001 From: Alexander Overvoorde Date: Sat, 31 Aug 2019 13:44:23 +0200 Subject: [PATCH] Add ALLOW_CORS parameter --- Dockerfile | 3 ++- README.md | 13 +++++++++++++ apache.conf | 4 ++++ run.sh | 5 +++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 806e4f9..3acb3fa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -131,7 +131,8 @@ RUN mkdir /var/lib/mod_tile \ && mkdir /var/run/renderd \ && chown renderer /var/run/renderd RUN echo "LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so" >> /etc/apache2/conf-available/mod_tile.conf \ - && a2enconf mod_tile + && echo "LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so" >> /etc/apache2/conf-available/mod_headers.conf \ + && a2enconf mod_tile && a2enconf mod_headers COPY apache.conf /etc/apache2/sites-available/000-default.conf COPY leaflet-demo.html /var/www/html/index.html RUN ln -sf /proc/1/fd/1 /var/log/apache2/access.log \ diff --git a/README.md b/README.md index a8b5a64..c8efc32 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,19 @@ docker run \ This will enable a background process that automatically downloads changes from the OpenStreetMap server, filters them for the relevant region polygon you specified, updates the database and finally marks the affected tiles for rerendering. +### Cross-origin resource sharing + +To enable the `Access-Control-Allow-Origin` header to be able to retrieve tiles from other domains, simply set the `ALLOW_CORS` variable to `1`: + +``` +docker run \ + -p 80:80 \ + -v openstreetmap-data:/var/lib/postgresql/10/main \ + -e ALLOW_CORS=1 \ + -d overv/openstreetmap-tile-server \ + run +``` + ## Performance tuning and tweaking Details for update procedure and invoked scripts can be found here [link](https://ircama.github.io/osm-carto-tutorials/updating-data/). diff --git a/apache.conf b/apache.conf index 77d1627..99b1615 100644 --- a/apache.conf +++ b/apache.conf @@ -10,4 +10,8 @@ ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined + + + Header set Access-Control-Allow-Origin "*" + diff --git a/run.sh b/run.sh index 0abe64d..857d847 100755 --- a/run.sh +++ b/run.sh @@ -69,6 +69,11 @@ if [ "$1" = "run" ]; then # Fix postgres data privileges chown postgres:postgres /var/lib/postgresql -R + # Configure Apache CORS + if [ "$ALLOW_CORS" == "1" ]; then + echo "export APACHE_ARGUMENTS='-D ALLOW_CORS'" >> /etc/apache2/envvars + fi + # Initialize PostgreSQL and Apache CreatePostgressqlConfig service postgresql start