diff --git a/Dockerfile b/Dockerfile index 3ff3d52..081fbf5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,10 @@ RUN npm run build RUN rm dist/playlist.json FROM nginx:alpine + +COPY static-env-handler.sh /docker-entrypoint.d/01-static-env-handler.sh +RUN chmod +x /docker-entrypoint.d/01-static-env-handler.sh + COPY --from=node-builder /app/dist /usr/share/nginx/html COPY nginx.conf /etc/nginx/conf.d/default.conf CMD ["nginx", "-g", "daemon off;"] diff --git a/README.md b/README.md index 8f49b18..5d3ef60 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,8 @@ Environment variables can be added to the command line as usual, or via a .env f Environment variables that are to be added to the default query string are prefixed with `WSQS_` and then use the same key/value pairs generated by the [Permalink](#sharing-a-permalink-bookmarking) above, with the `- (dash)` character replaced by an `_ (underscore)`. For example, if you wanted to turn the travel forecast on, you would find `travel-checkbox=true` in the permalink, its matching environment variable becomes `WSQS_travel_checkbox=true`. +When using the Docker container, these environment variables are read on container start-up to generate the static redirect HTML. + ## Music The WeatherStar had wonderful background music from the smooth jazz and new age genres by artists of the time. Lists of the music that played are available by searching online, but it's all copyrighted music and would be difficult to provide as part of this repository. @@ -165,6 +167,8 @@ Thanks to the WeatherStar community for providing these discussions to further e ## Customization A hook is provided as `/server/scripts/custom.js` to allow customizations to your own fork of this project, without accidentally pushing your customizations back upstream to the git repository. A sample file is provided at `/server/scripts/custom.sample.js` and should be renamed to `custom.js` activate it. +When using Docker, mount your `custom.js` file to `/usr/share/nginx/html/scripts/custom.js` to customize the static build. + ## Issue reporting and feature requests Please do not report issues with api.weather.gov being down. It's a new service and not considered fully operational yet. I've also observed that the API can go down on a regional basis (based on NWS office locations). This means that you may have problems getting data for, say, Chicago right now, but Dallas and others are working just fine. diff --git a/nginx.conf b/nginx.conf index 207aac9..c197c90 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,11 +1,11 @@ server { - listen 80; + listen 8080; server_name localhost; root /usr/share/nginx/html; location / { - index index.html index.htm; + index redirect.html index.html index.htm; try_files $uri $uri/ =404; } diff --git a/static-env-handler.sh b/static-env-handler.sh new file mode 100644 index 0000000..247c0e5 --- /dev/null +++ b/static-env-handler.sh @@ -0,0 +1,39 @@ +#!/bin/sh +set -eu + +ROOT="/usr/share/nginx/html" +QS="" + +# build query string from WSQS_ env vars +for var in $(env); do + case "$var" in + WSQS_*=*) + key="${var%%=*}" + val="${var#*=}" + key="${key#WSQS_}" + key="${key//_/-}" + if [ -n "$QS" ]; then + QS="$QS&${key}=${val}" + else + QS="${key}=${val}" + fi + ;; + esac +done + + +if [ -n "$QS" ]; then + cat > "$ROOT/redirect.html" < + + + + Redirecting + + + + +EOF +fi + +exec nginx -g 'daemon off;'