|
| 1 | +# Caddyfile for StringSight API |
| 2 | +# Optimized for Vercel → Digital Ocean connections |
| 3 | +# Deploy this to your droplet at /etc/caddy/Caddyfile |
| 4 | + |
| 5 | +api.stringsight.com { |
| 6 | + # Reverse proxy to your uvicorn backend |
| 7 | + reverse_proxy localhost:8000 { |
| 8 | + # Connection pooling - keeps connections alive |
| 9 | + transport http { |
| 10 | + keepalive 90s |
| 11 | + keepalive_idle_conns 10 |
| 12 | + } |
| 13 | + |
| 14 | + # Health check to verify backend is up |
| 15 | + health_uri /health |
| 16 | + health_interval 30s |
| 17 | + health_timeout 5s |
| 18 | + } |
| 19 | + |
| 20 | + # CORS configuration for Vercel frontend |
| 21 | + @cors_preflight { |
| 22 | + method OPTIONS |
| 23 | + } |
| 24 | + |
| 25 | + # Handle CORS preflight quickly (this is KEY for performance!) |
| 26 | + handle @cors_preflight { |
| 27 | + header Access-Control-Allow-Origin "https://stringsight.vercel.app" |
| 28 | + header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" |
| 29 | + header Access-Control-Allow-Headers "DNT, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Range, Authorization" |
| 30 | + header Access-Control-Max-Age "86400" # Cache preflight for 24 hours |
| 31 | + respond 204 |
| 32 | + } |
| 33 | + |
| 34 | + # CORS headers for all responses |
| 35 | + header Access-Control-Allow-Origin "https://stringsight.vercel.app" |
| 36 | + header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" |
| 37 | + header Access-Control-Allow-Headers "DNT, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Range, Authorization" |
| 38 | + header Access-Control-Expose-Headers "Content-Length, Content-Range" |
| 39 | + header Access-Control-Allow-Credentials "true" |
| 40 | + |
| 41 | + # Increase request size limit for file uploads |
| 42 | + request_body { |
| 43 | + max_size 100MB |
| 44 | + } |
| 45 | + |
| 46 | + # Enable compression for API responses |
| 47 | + encode gzip |
| 48 | + |
| 49 | + # Logging |
| 50 | + log { |
| 51 | + output file /var/log/caddy/stringsight.log |
| 52 | + format json |
| 53 | + level INFO |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +# Optional: If you want to serve frontend from the same domain |
| 58 | +# www.stringsight.com, stringsight.com { |
| 59 | +# root * /var/www/stringsight |
| 60 | +# file_server |
| 61 | +# try_files {path} /index.html |
| 62 | +# } |
0 commit comments