-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCaddyfile
More file actions
222 lines (208 loc) · 6.79 KB
/
Copy pathCaddyfile
File metadata and controls
222 lines (208 loc) · 6.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# Hermes Reverse Proxy Configuration
#
# This file controls how requests are routed to your Hermes services.
# You can customize this for your domain, SSL certificates, and routing rules.
#
# Quick Start:
# - For local development: Leave as-is
# - For production with domain: Replace :80 with your domain (e.g., hermes.yourdomain.com)
# - Caddy will automatically obtain Let's Encrypt certificates for domains
# Basic HTTP configuration (default - works locally)
:80 {
# Health check endpoint (for load balancers and monitoring)
handle /health {
respond "healthy" 200
}
# SSE Events endpoint - MUST come before general API handler
# Critical: flush_interval -1 prevents buffering of SSE events
handle /api/v1/events/* {
reverse_proxy api:8000 {
# Forward client information headers
header_up X-Real-IP {remote_host}
header_up X-Forwarded-For {remote_host}
header_up X-Forwarded-Proto {scheme}
header_up X-Forwarded-Host {host}
# CRITICAL for SSE: Disable buffering
flush_interval -1
# Keep connection alive for SSE
transport http {
keepalive 90s
keepalive_idle_conns 10
}
}
}
# API routes - proxy to backend service
handle /api/* {
reverse_proxy api:8000 {
# Forward client information headers
header_up X-Real-IP {remote_host}
header_up X-Forwarded-For {remote_host}
header_up X-Forwarded-Proto {scheme}
header_up X-Forwarded-Host {host}
# Health checks for the backend
health_uri /api/v1/health/
health_interval 30s
health_timeout 10s
}
}
# Frontend - serve static files
handle {
root * /app
# Try to serve file, fallback to index.html for SPA routing
try_files {path} /index.html
file_server
# Cache static assets aggressively
@static {
path *.js *.css *.png *.jpg *.jpeg *.gif *.ico *.svg *.woff *.woff2 *.ttf *.eot
}
header @static {
Cache-Control "public, max-age=31536000, immutable"
}
# Security headers for all responses
header {
X-Frame-Options "SAMEORIGIN"
X-Content-Type-Options "nosniff"
X-XSS-Protection "1; mode=block"
Referrer-Policy "strict-origin-when-cross-origin"
# Note: Strict CSP might need adjustment based on your needs
}
# Don't cache HTML files
@html {
path *.html /
}
header @html {
Cache-Control "no-cache, no-store, must-revalidate"
}
}
# Optional: Enable access logging for debugging
# Uncomment the lines below to log requests
# log {
# output file /var/log/caddy/access.log
# format json
# }
}
# ==============================================================================
# PRODUCTION CONFIGURATION EXAMPLE
# ==============================================================================
#
# Uncomment and customize the section below for production deployment with a domain.
# Caddy will automatically obtain and renew Let's Encrypt SSL certificates.
#
# ==============================================================================
# SEPARATE DOMAINS EXAMPLE
# ==============================================================================
# For separate API and frontend domains (e.g., hermes-api.example.com and hermes.example.com)
#
# hermes-api.example.com {
# # Caddy automatically enables HTTPS and obtains certificates
# tls admin@example.com
#
# # Health check
# handle /health {
# respond "healthy" 200
# }
#
# # API routes only
# handle /api/v1/* {
# reverse_proxy api:8000 {
# header_up X-Real-IP {remote_host}
# header_up X-Forwarded-For {remote_host}
# header_up X-Forwarded-Proto {scheme}
# header_up X-Forwarded-Host {host}
#
# # Health checks for the backend
# health_uri /api/v1/health/
# health_interval 30s
# health_timeout 10s
# }
# }
#
# # Block all other requests
# handle {
# respond "Not Found" 404
# }
# }
#
# hermes.example.com {
# # Caddy automatically enables HTTPS and obtains certificates
# tls admin@example.com
#
# # Redirect API calls to separate API domain
# handle /api/* {
# redir https://hermes-api.example.com{uri} permanent
# }
#
# # Frontend static files
# handle {
# root * /app
# try_files {path} /index.html
# file_server
#
# @static {
# path *.js *.css *.png *.jpg *.jpeg *.gif *.ico *.svg *.woff *.woff2 *.ttf *.eot
# }
# header @static Cache-Control "public, max-age=31536000, immutable"
#
# header {
# X-Frame-Options "SAMEORIGIN"
# X-Content-Type-Options "nosniff"
# Referrer-Policy "strict-origin-when-cross-origin"
# Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
# }
# }
# }
#
# ==============================================================================
# SINGLE DOMAIN EXAMPLE
# ==============================================================================
# For single domain with API proxy (e.g., hermes.example.com)
#
# hermes.example.com {
# # Caddy automatically enables HTTPS and obtains certificates
# tls admin@example.com
#
# # Health check
# handle /health {
# respond "healthy" 200
# }
#
# # API proxy
# handle /api/* {
# reverse_proxy api:8000 {
# header_up X-Real-IP {remote_host}
# header_up X-Forwarded-For {remote_host}
# header_up X-Forwarded-Proto {scheme}
# header_up X-Forwarded-Host {host}
#
# # Health checks for the backend
# health_uri /api/v1/health/
# health_interval 30s
# health_timeout 10s
# }
# }
#
# # Frontend static files
# handle {
# root * /app
# try_files {path} /index.html
# file_server
#
# @static {
# path *.js *.css *.png *.jpg *.jpeg *.gif *.ico *.svg *.woff *.woff2 *.ttf *.eot
# }
# header @static Cache-Control "public, max-age=31536000, immutable"
#
# header {
# X-Frame-Options "SAMEORIGIN"
# X-Content-Type-Options "nosniff"
# Referrer-Policy "strict-origin-when-cross-origin"
# Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
# }
# }
#
# # Enable access logs
# log {
# output file /data/access.log
# format json
# }
# }