serve api on same origin at /api

This commit is contained in:
2025-10-29 01:52:48 +01:00
parent 3bdca88144
commit 0052dff119
8 changed files with 71 additions and 56 deletions
+31 -5
View File
@@ -1,11 +1,37 @@
#!/bin/sh
set -euo pipefail
API_BASE_URL_TRIMMED="${API_BASE_URL:-}"
API_BASE_URL_TRIMMED="${API_BASE_URL_TRIMMED%%/}"
API_PROXY_PASS_TRIMMED="${API_PROXY_PASS:-}"
API_PROXY_PASS_TRIMMED="${API_PROXY_PASS_TRIMMED%%/}"
cat <<CONFIG > /usr/share/nginx/html/config.js
window.__PAPERCRATE_API_BASE_URL = "${API_BASE_URL_TRIMMED}";
CONFIG
cat <<'BASE' > /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri /index.html;
}
BASE
if [ -n "$API_PROXY_PASS_TRIMMED" ]; then
cat <<PROXY >> /etc/nginx/conf.d/default.conf
location /api/ {
proxy_pass ${API_PROXY_PASS_TRIMMED};
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
fi
cat <<'ENDCFG' >> /etc/nginx/conf.d/default.conf
}
ENDCFG
exec "$@"