|
| 1 | +# Run with |
| 2 | +# caddy run --envfile ./example.env --config ./Caddyfile.localhost |
| 3 | +# |
| 4 | +# This is configured for |
| 5 | +# - Automatic HTTPS (even for localhost) |
| 6 | +# - Reverse Proxying to Ollama API Base URL (http://localhost:11434/api) |
| 7 | +# - CORS |
| 8 | +# - HTTP Basic Auth API Tokens (uncomment basicauth section) |
| 9 | + |
| 10 | + |
| 11 | +# CORS Preflight (OPTIONS) + Request (GET, POST, PATCH, PUT, DELETE) |
| 12 | +(cors-api) { |
| 13 | + @match-cors-api-preflight method OPTIONS |
| 14 | + handle @match-cors-api-preflight { |
| 15 | + header { |
| 16 | + Access-Control-Allow-Origin "{http.request.header.origin}" |
| 17 | + Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS" |
| 18 | + Access-Control-Allow-Headers "Origin, Accept, Authorization, Content-Type, X-Requested-With" |
| 19 | + Access-Control-Allow-Credentials "true" |
| 20 | + Access-Control-Max-Age "3600" |
| 21 | + defer |
| 22 | + } |
| 23 | + respond "" 204 |
| 24 | + } |
| 25 | + |
| 26 | + @match-cors-api-request { |
| 27 | + not { |
| 28 | + header Origin "{http.request.scheme}://{http.request.host}" |
| 29 | + } |
| 30 | + header Origin "{http.request.header.origin}" |
| 31 | + } |
| 32 | + handle @match-cors-api-request { |
| 33 | + header { |
| 34 | + Access-Control-Allow-Origin "{http.request.header.origin}" |
| 35 | + Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS" |
| 36 | + Access-Control-Allow-Headers "Origin, Accept, Authorization, Content-Type, X-Requested-With" |
| 37 | + Access-Control-Allow-Credentials "true" |
| 38 | + Access-Control-Max-Age "3600" |
| 39 | + defer |
| 40 | + } |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +# replace localhost with example.com or whatever |
| 45 | +localhost { |
| 46 | + ## HTTP Basic Auth |
| 47 | + ## (uncomment to enable) |
| 48 | + # basicauth { |
| 49 | + # # see .example.env for how to generate tokens |
| 50 | + # {env.OLLAMA_API_ID} {env.OLLAMA_API_TOKEN_DIGEST} |
| 51 | + # } |
| 52 | + |
| 53 | + handle /api/* { |
| 54 | + # Comment to disable CORS |
| 55 | + import cors-api |
| 56 | + |
| 57 | + reverse_proxy localhost:11434 |
| 58 | + } |
| 59 | + |
| 60 | + # Same-Origin Static Web Server |
| 61 | + file_server { |
| 62 | + root ./build/ |
| 63 | + } |
| 64 | +} |
0 commit comments