mirror of
https://github.com/hanzoai/pack.git
synced 2026-09-30 23:43:13 +00:00
* feat(staticfile): add configurable index fallback for SPAs - Fixes #https://github.com/railwayapp/railpack/issues/533 - Introduce index_fallback option in Staticfile config to toggle SPA routing. - Improve root directory detection by trimming whitespace from environment variables and configuration. * feat: add index fallback example for static files - Create a new example directory demonstrating the index_fallback configuration. - Include a test case to verify that non-existent routes correctly serve index.html. Generated-by: aiautocommit * test: update snapshots Generated-by: aiautocommit * test: update static file config and index test cases Generated-by: aiautocommit * test: add SPA index fallback verification to test suite Generated-by: aiautocommit * docs: document RAILPACK_VERBOSE and clarify Staticfile config Generated-by: aiautocommit
58 lines
1.3 KiB
Caddyfile
58 lines
1.3 KiB
Caddyfile
{
|
|
admin off
|
|
persist_config off
|
|
auto_https off
|
|
|
|
log {
|
|
format json
|
|
}
|
|
|
|
servers {
|
|
trusted_proxies static private_ranges
|
|
}
|
|
}
|
|
|
|
:{$PORT:80} {
|
|
log {
|
|
format json
|
|
}
|
|
|
|
respond /health 200
|
|
|
|
# Security headers
|
|
header {
|
|
# Enable cross-site filter (XSS) and tell browsers to block detected attacks
|
|
X-XSS-Protection "1; mode=block"
|
|
# Prevent some browsers from MIME-sniffing a response away from the declared Content-Type
|
|
X-Content-Type-Options "nosniff"
|
|
# Keep referrer data off of HTTP connections
|
|
Referrer-Policy "strict-origin-when-cross-origin"
|
|
# Enable strict Content Security Policy
|
|
Content-Security-Policy "default-src 'self'; img-src 'self' data: https: *; style-src 'self' 'unsafe-inline' https: *; script-src 'self' 'unsafe-inline' https: *; font-src 'self' data: https: *; connect-src 'self' https: *; media-src 'self' https: *; object-src 'none'; frame-src 'self' https: *;"
|
|
# Remove Server header
|
|
-Server
|
|
}
|
|
|
|
root * {{.StaticFileRoot}}
|
|
|
|
# Handle static files
|
|
file_server {
|
|
hide .git
|
|
hide .env*
|
|
}
|
|
|
|
# Compression with more formats
|
|
encode {
|
|
gzip
|
|
zstd
|
|
}
|
|
|
|
# Try files with HTML extension{{if .IndexFallback}} and handle SPA routing{{end}}
|
|
try_files {path} {path}.html {path}/index.html{{if .IndexFallback}} /index.html{{end}}
|
|
|
|
handle_errors {
|
|
rewrite * /{err.status_code}.html
|
|
file_server
|
|
}
|
|
}
|