#!/bin/bash set -euo pipefail # Make public writable so env.sh can write env-config.js chmod -R a+rw ./public || true # Run env.sh if present if [ -x ./env.sh ]; then ./env.sh || true fi # Copy nginx config from mounted source if available so dev config can be # edited on the host without rebuilding the image. Priority: # 1) ./conf/conf.d/default.conf (project's conf folder) # 2) ./nginx.dev.conf (bundled with the dev image at build time) if [ -f /app/conf/conf.d/default.conf ]; then echo "Using nginx config from /app/conf/conf.d/default.conf (creating dev variant)" # Backup original cp /app/conf/conf.d/default.conf /app/conf/conf.d/default.conf.backup || true # Write a deterministic dev nginx config that proxies known API routes to # the backend and proxies '/' to the CRA dev server so HMR works through nginx. cat > /etc/nginx/conf.d/default.conf <<'NGINXDEV' server { listen 80 default_server; listen [::]:80 default_server; client_max_body_size 200M; location /upload { proxy_pass http://image-uploader-backend:5000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; client_max_body_size 200M; } location /api/upload { proxy_pass http://image-uploader-backend:5000/upload; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; client_max_body_size 200M; } location /api/groups { proxy_pass http://image-uploader-backend:5000/groups; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } location /moderation/groups { proxy_pass http://image-uploader-backend:5000/moderation/groups; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } location ~ ^/groups/[a-zA-Z0-9_-]+(/.*)?$ { proxy_pass http://image-uploader-backend:5000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } location /download { proxy_pass http://image-uploader-backend:5000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } # Proxy webpack dev server (supports HMR / WebSocket upgrades) location /sockjs-node/ { proxy_pass http://127.0.0.1:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location / { proxy_pass http://127.0.0.1:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } NGINXDEV elif [ -f /app/nginx.dev.conf ]; then echo "Using bundled nginx.dev.conf" cp /app/nginx.dev.conf /etc/nginx/conf.d/default.conf || true fi # Ensure node cache exists and is writable mkdir -p /app/node_modules/.cache || true chmod -R a+rw /app/node_modules || true # Ensure HOST is set so CRA binds to 0.0.0.0 export HOST=${HOST:-0.0.0.0} # Start the React development server in background npm run dev & DEV_PID=$! # Start nginx in foreground so container stays alive; nginx will proxy to the dev server exec nginx -g 'daemon off;'