From bc07e8151498f0ddfd820239f523cae862b1fce9 Mon Sep 17 00:00:00 2001 From: Andre Cobham Date: Thu, 4 Jun 2026 00:30:40 +0100 Subject: [PATCH] Fix contact form POST routing and bake env into build - nginx: route POST /contact/ to contact.php, GET to router.php - Dockerfile: COPY .env into image - entrypoint.sh: source .env on container start - .dockerignore: allow .env to be included in build context --- .dockerignore | 3 +-- Dockerfile | 1 + infra/entrypoint.sh | 3 +++ infra/nginx.conf | 10 ++++++++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.dockerignore b/.dockerignore index 5f51686..5cabdc7 100755 --- a/.dockerignore +++ b/.dockerignore @@ -7,8 +7,7 @@ __pycache__ *.pyc *.md *.txt -.env -.env.* +.env.example !robots.txt *.xml !sitemap.xml diff --git a/Dockerfile b/Dockerfile index 614eb7b..ed6c80e 100755 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,7 @@ COPY robots.txt /var/www/html/robots.txt COPY sitemap.xml /var/www/html/sitemap.xml COPY 404.html /var/www/html/404.html COPY 500.html /var/www/html/500.html +COPY .env /var/www/html/.env RUN chown -R www-data:www-data /var/www/html diff --git a/infra/entrypoint.sh b/infra/entrypoint.sh index e24ab27..b20732c 100755 --- a/infra/entrypoint.sh +++ b/infra/entrypoint.sh @@ -1,5 +1,8 @@ #!/bin/sh set -e +if [ -f /var/www/html/.env ]; then + set -a; . /var/www/html/.env; set +a +fi if [ -z "$ALTCHA_HMAC_KEY" ]; then export ALTCHA_HMAC_KEY="$(openssl rand -hex 32)" echo "Generated ALTCHA_HMAC_KEY" >&2 diff --git a/infra/nginx.conf b/infra/nginx.conf index e699701..4d634ef 100755 --- a/infra/nginx.conf +++ b/infra/nginx.conf @@ -81,8 +81,14 @@ http { limit_req zone=contact_limit burst=3 nodelay; limit_req_status 429; include fastcgi_params; - fastcgi_param SCRIPT_FILENAME /var/www/html/src/api/router.php; - fastcgi_param QUERY_STRING type=page&slug=contact; + set $contact_script /var/www/html/src/api/router.php; + set $contact_query "type=page&slug=contact"; + if ($request_method = POST) { + set $contact_script /var/www/html/src/api/contact.php; + set $contact_query ""; + } + fastcgi_param SCRIPT_FILENAME $contact_script; + fastcgi_param QUERY_STRING $contact_query; fastcgi_pass 127.0.0.1:9000; }