Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions caddy/Caddyfile.local
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@
format console
}

header {
Access-Control-Allow-Origin "http://localhost:5173" # allows the Vue app (running on localhost:5173) to make requests.
Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" # Specifies which methods are allowed.
Access-Control-Allow-Headers "X-API-Key, X-API-Username, X-API-Signature, Content-Type, User-Agent" # allows the custom headers needed by the API.
}

# This handles the browser's "preflight" OPTIONS request.
@preflight {
method OPTIONS
header Origin *
}

handle @preflight {
# Reflect the Origin back so it's always allowed
header Access-Control-Allow-Origin "{http.request.header.Origin}"
header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
header Access-Control-Allow-Headers "X-API-Key, X-API-Username, X-API-Signature, Content-Type, User-Agent"
header Access-Control-Max-Age "86400"
respond 204
}

# Reverse proxy all incoming requests to the 'api' service.
# - The service name 'api' is resolved by Docker's internal DNS to the correct container IP on the 'caddy_net' network.
# - The API container listens on port 8080 (from the ENV_HTTP_PORT).
Expand Down
20 changes: 20 additions & 0 deletions caddy/Caddyfile.prod
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ oullin.io {
# - header_up: Preserve the original Host header.
# - header_up X-*: Forward the client headers.
handle_path /api/* {
header {
Access-Control-Allow-Origin "https://oullin.io"
Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
Access-Control-Allow-Headers "X-API-Key, X-API-Username, X-API-Signature, Content-Type, User-Agent"
}

@preflight {
method OPTIONS
header Origin *
}

handle @preflight {
# Reflect the Origin back so it's always allowed
header Access-Control-Allow-Origin "{http.request.header.Origin}"
header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
header Access-Control-Allow-Headers "X-API-Key, X-API-Username, X-API-Signature, Content-Type, User-Agent"
header Access-Control-Max-Age "86400"
respond 204
}

reverse_proxy api:8080 {
header_up Host {host}
header_up X-API-Username {http.request.header.X-API-Username}
Expand Down
Loading