64 lines
1.3 KiB
Bash
Executable File
64 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
CONFIG_FILE="/opt/appfactory/config/appfactory.env"
|
|
source "$CONFIG_FILE"
|
|
|
|
CATALOG_FILE="$APPFACTORY_DIR/apps/catalog.yml"
|
|
CADDY_FILE="$APPFACTORY_DIR/gateway/Caddyfile"
|
|
|
|
mkdir -p "$(dirname "$CADDY_FILE")"
|
|
|
|
cat > "$CADDY_FILE" <<EOF_CADDY
|
|
:80 {
|
|
handle /health {
|
|
respond "AppFactory OK" 200
|
|
}
|
|
|
|
handle /portal* {
|
|
uri strip_prefix /portal
|
|
reverse_proxy appfactory-portal:9100
|
|
}
|
|
|
|
handle /apps {
|
|
root * /srv/static
|
|
rewrite * /apps.html
|
|
file_server
|
|
}
|
|
|
|
EOF_CADDY
|
|
|
|
if [ -f "$CATALOG_FILE" ]; then
|
|
awk '
|
|
/^[[:space:]]*-[[:space:]]id:/ {
|
|
app=$3
|
|
|
|
print " handle_path /apps/" app "/* {"
|
|
print " reverse_proxy " app ":8000"
|
|
print " }"
|
|
print ""
|
|
}
|
|
' "$CATALOG_FILE" >> "$CADDY_FILE"
|
|
fi
|
|
|
|
cat >> "$CADDY_FILE" <<EOF_CADDY
|
|
handle_path /webhook/* {
|
|
reverse_proxy appfactory-webhook:9000
|
|
}
|
|
|
|
handle_path /registry/* {
|
|
reverse_proxy appfactory-registry:5000
|
|
}
|
|
|
|
handle {
|
|
respond "AppFactory gateway is running" 200
|
|
}
|
|
}
|
|
EOF_CADDY
|
|
|
|
echo "Generated: $CADDY_FILE"
|
|
|
|
docker exec appfactory-caddy caddy validate --config /etc/caddy/Caddyfile
|
|
|
|
docker exec appfactory-caddy caddy reload --config /etc/caddy/Caddyfile
|