Caddy `templates` only processes text/html + text/plain by default, so the
text/javascript env.js was served with {{env "API_BASE"}} unevaluated (a literal
that's also a JS parse error). Name the JS MIME types in the templates directive
so the API_BASE injection works — required for prod to point at the prod API
(staging worked only via the index.html fallback).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
33 lines
1.1 KiB
Caddyfile
33 lines
1.1 KiB
Caddyfile
# FleetOps — static analytics SPA served by Caddy.
|
|
# Traefik (via Coolify) terminates TLS, so Caddy is a plain :80 file server.
|
|
# The only moving part is runtime API-base injection: Caddy's `templates`
|
|
# directive evaluates {{env "API_BASE"}} inside /env.js at request time, so the
|
|
# SAME image serves staging (fleetapi.fivetitude.com) and prod
|
|
# (fleetapi.rahamafresh.com) — set API_BASE per Coolify app.
|
|
:80 {
|
|
root * /srv
|
|
encode zstd gzip
|
|
|
|
# Health endpoint for Coolify / Traefik probes.
|
|
handle /healthz {
|
|
respond "ok" 200
|
|
}
|
|
|
|
# Runtime config: Caddy renders {{env "API_BASE"}} into env.js. Never cache it.
|
|
# `templates` only acts on text/html + text/plain by default, so JS responses
|
|
# are skipped unless their MIME type is named explicitly here.
|
|
handle /env.js {
|
|
header Cache-Control "no-store"
|
|
templates {
|
|
mime text/javascript application/javascript
|
|
}
|
|
file_server
|
|
}
|
|
|
|
# SPA: never cache the shell, fall back to index.html for client routes.
|
|
handle {
|
|
header /index.html Cache-Control "no-store"
|
|
try_files {path} /index.html
|
|
file_server
|
|
}
|
|
}
|