mirror of
https://github.com/hanzo-fi/stack.git
synced 2026-10-30 20:34:43 +00:00
112 lines
3.1 KiB
Caddyfile
112 lines
3.1 KiB
Caddyfile
(cors) {
|
|
header {
|
|
Access-Control-Allow-Methods "GET,OPTIONS,PUT,POST,DELETE,HEAD,PATCH"
|
|
Access-Control-Allow-Headers content-type
|
|
Access-Control-Max-Age 100
|
|
Access-Control-Allow-Origin *
|
|
}
|
|
}
|
|
{{- $values := . }}
|
|
{{- if .EnableAudit }}
|
|
(audit) {
|
|
audit {
|
|
# Kafka publisher
|
|
{{- if (eq .Broker "kafka") }}
|
|
publisher_kafka_broker {$PUBLISHER_KAFKA_BROKER:redpanda:29092}
|
|
publisher_kafka_enabled {$PUBLISHER_KAFKA_ENABLED:false}
|
|
publisher_kafka_tls_enabled {$PUBLISHER_KAFKA_TLS_ENABLED:false}
|
|
publisher_kafka_sasl_enabled {$PUBLISHER_KAFKA_SASL_ENABLED:false}
|
|
publisher_kafka_sasl_username {$PUBLISHER_KAFKA_SASL_USERNAME}
|
|
publisher_kafka_sasl_password {$PUBLISHER_KAFKA_SASL_PASSWORD}
|
|
publisher_kafka_sasl_mechanism {$PUBLISHER_KAFKA_SASL_MECHANISM}
|
|
publisher_kafka_sasl_scram_sha_size {$PUBLISHER_KAFKA_SASL_SCRAM_SHA_SIZE}
|
|
{{- end }}
|
|
{{- if (eq .Broker "nats") }}
|
|
# Nats publisher
|
|
publisher_nats_enabled {$PUBLISHER_NATS_ENABLED:true}
|
|
publisher_nats_url {$PUBLISHER_NATS_URL:nats://nats:4222}
|
|
publisher_nats_client_id {$PUBLISHER_NATS_CLIENT_ID:gateway}
|
|
publisher_nats_max_reconnects {$PUBLISHER_NATS_MAX_RECONNECTS:30}
|
|
publisher_nats_max_reconnects_wait {$PUBLISHER_NATS_MAX_RECONNECT_WAIT:2s}
|
|
{{- end }}
|
|
}
|
|
}
|
|
{{- end }}
|
|
|
|
{
|
|
{{ if .Debug }}debug{{ end }}
|
|
servers {
|
|
metrics
|
|
}
|
|
admin :3080
|
|
|
|
# Many directives manipulate the HTTP handler chain and the order in which
|
|
# those directives are evaluated matters. So the jwtauth directive must be
|
|
# ordered.
|
|
# c.f. https://caddyserver.com/docs/caddyfile/directives#directive-order
|
|
order versions after metrics
|
|
{{- if .EnableAudit }}
|
|
order audit after encode
|
|
{{- end }}
|
|
}
|
|
|
|
:{{ .Port }} {
|
|
{{- if .EnableOpenTelemetry }}
|
|
tracing {
|
|
span gateway
|
|
}
|
|
{{- end }}
|
|
log {
|
|
output stdout
|
|
{{- if .Debug }}
|
|
level DEBUG
|
|
{{- end }}
|
|
}
|
|
|
|
{{- if .EnableAudit }}
|
|
import audit
|
|
{{- end }}
|
|
|
|
{{- range $i, $service := .Services }}
|
|
{{- range $j, $rule := $service.Rules }}
|
|
handle /api/{{ $service.Name }}{{ $rule.Path }}* {
|
|
{{- if $rule.Methods }}
|
|
method {{ join $rule.Methods " " }}
|
|
{{- end }}
|
|
uri strip_prefix /api/{{ $service.Name }}
|
|
import cors
|
|
reverse_proxy {{ $service.Name }}:8080 {
|
|
header_up Host {upstream_hostport}
|
|
}
|
|
}
|
|
{{- end }}
|
|
{{- end }}
|
|
|
|
handle /versions {
|
|
versions {
|
|
region "{{ .Platform.Region }}"
|
|
env "{{ .Platform.Environment }}"
|
|
endpoints {
|
|
{{- range $i, $service := .Services }}
|
|
{{- $healthCheckEndpoint := $service.HealthCheckEndpoint }}
|
|
{{- if eq $healthCheckEndpoint "" }}
|
|
{{- $healthCheckEndpoint = "_healthcheck" }}
|
|
{{- end }}
|
|
|
|
{{- if or (not (semver_is_valid $values.Gateway.Version)) (gt (semver_compare $values.Gateway.Version "v0.1.7") 0) }}
|
|
{{ $service.Name }} {
|
|
http://{{ $service.Name }}:8080/_info http://{{ $service.Name }}:8080/{{ $service.HealthCheckEndpoint }}
|
|
}
|
|
{{- else }}
|
|
{{ $service.Name }} http://{{ $service.Name }}:8080/_info http://{{ $service.Name }}:8080/{{ $service.HealthCheckEndpoint }}
|
|
{{- end }}
|
|
{{- end }}
|
|
}
|
|
}
|
|
}
|
|
|
|
# Respond 404 if service does not exists
|
|
handle /api/* {
|
|
respond "Not Found" 404
|
|
}
|
|
} |