···1313 }
1414}
15151616+(lb_settings) {
1717+ lb_policy round_robin
1818+ lb_retries 100
1919+ lb_try_duration 10s
2020+ lb_try_interval 250ms
2121+}
2222+2323+(passive_health_checks) {
2424+ fail_duration 60s
2525+ max_fails 300
2626+ unhealthy_latency 5s
2727+ unhealthy_request_count 200
2828+}
2929+1630# site block, listens on the $PORT environment variable, automatically assigned by railway
1731:{$PORT} {
1832 # access logs
···2034 format json # set access log format to json mode
2135 }
22362323- reverse_proxy {$FRONTEND_HOST} # proxy all requests for /* to the frontend, configure this variable in the service settings
3737+ # proxy all requests for /* to the frontend, configure these variables in the service settings
3838+ reverse_proxy {
3939+ # for private networking replicas are exposed as multiple dns results, use those dns results as the upstreams
4040+ dynamic a {
4141+ name {$FRONTEND_DOMAIN}
4242+ port {$FRONTEND_PORT}
4343+ refresh 1s
4444+ dial_timeout 30s
4545+ versions ipv4 ipv6
4646+ }
4747+4848+ # configure load balancing settings
4949+ import lb_settings
5050+5151+ # configure passive health checks
5252+ import passive_health_checks
5353+5454+ # sets the Host header to the header to the dynamic name and port options
5555+ header_up Host {upstream_hostport}
5656+ }
24572558 # the handle_path directive WILL strip /api/ from the path before proxying
5959+ # use `handle` instead of `handle_path` if you dont want to strip the /api/ path
2660 # this is needed if your backend's api routes don't start with /api/
2761 # change paths as needed
2828- handle_path /api/* {
6262+ handle_path {$BACKEND_PATH:/api}/* {
2963 # the /api/ prefix WILL be stripped from the uri sent to the proxy host
3030- reverse_proxy {$BACKEND_HOST} # proxy all requests for /api/* to the backend, configure this variable in the service settings
3131- }
6464+ #
6565+ # proxy all requests for /api/* to the backend, configure this variable in the service settings
6666+ reverse_proxy {
6767+ # for private networking replicas are exposed as multiple dns results, use those dns results as the upstreams
6868+ dynamic a {
6969+ name {$BACKEND_DOMAIN}
7070+ port {$BACKEND_PORT}
7171+ refresh 1s
7272+ dial_timeout 30s
7373+ versions ipv4 ipv6
7474+ }
32753333- # this handle directive will NOT strip /api/ from the path before proxying
3434- # if your backend's api routes do start with /api/ then you wouldn't want to strip the path prefix
3535- # if so, comment out the above handle_path and reverse_proxy directives, and uncomment these handle and reverse_proxy directives
3636- # change paths as needed
3737- # handle /api/* {
3838- # the /api/ prefix will NOT be stripped from the uri sent to the proxy host
3939- # reverse_proxy {$BACKEND_HOST} # proxy all requests for /api/* to the backend, configure this variable in the service settings
4040- # }
7676+ # configure load balancing settings
7777+ import lb_settings
7878+7979+ # configure passive health checks
8080+ import passive_health_checks
8181+8282+ # sets the Host header to the header to the dynamic name and port options
8383+ header_up Host {upstream_hostport}
8484+ }
8585+ }
4186}
···11+#!/bin/sh
22+33+set -euo pipefail
44+55+# for backwards compatibility, seperates host and port from url
66+export FRONTEND_DOMAIN=${FRONTEND_DOMAIN:-${FRONTEND_HOST%:*}}
77+export FRONTEND_PORT=${FRONTEND_PORT:-${FRONTEND_HOST##*:}}
88+99+export BACKEND_DOMAIN=${BACKEND_DOMAIN:-${BACKEND_HOST%:*}}
1010+export BACKEND_PORT=${BACKEND_PORT:-${BACKEND_HOST##*:}}
1111+1212+# strip https:// or https:// from domain if necessary
1313+FRONTEND_DOMAIN=${FRONTEND_DOMAIN##*://}
1414+BACKEND_DOMAIN=${BACKEND_DOMAIN##*://}
1515+1616+echo using frontend: ${FRONTEND_DOMAIN} with port: ${FRONTEND_PORT}
1717+echo using backend: ${BACKEND_DOMAIN} with port: ${BACKEND_PORT}
1818+1919+exec caddy run --config Caddyfile --adapter caddyfile 2>&1