Skip to content

Instantly share code, notes, and snippets.

@17twenty
Created March 15, 2024 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 17twenty/0d5ff06ca65a7de9f7205194a9e24b20 to your computer and use it in GitHub Desktop.
Save 17twenty/0d5ff06ca65a7de9f7205194a9e24b20 to your computer and use it in GitHub Desktop.
# Example routing with 3 apps
# We have three moving parts:
# Region specific API server (prefix papi.us.getfeewise.com)
# Region specific Dashboard App ( dashboard.getfeewise.com/us/* ) - tricky
# Region specific Customer App ( us.getfeewise.com )
# This makes s3proxy work
{
order s3proxy last
}
# We could use this but we need keychain creds and a bucket
# https://github.com/lindenlab/caddy-s3-proxy/blob/master/README.md#credentials
# I built a custom Caddy build for this via their website... pretty neat!
s3.getfeewise.localhost {
s3proxy {
# uri strip_prefix /dev
region "us-east-2"
bucket "our-bucket"
index index.html
# force_path_style
}
}
# Abuse rewrite and use header_up to ensure
# we can reroute to an s3 bucket
# In this case, poor Rubio
# https://s3.us-east-2.amazonaws.com/blondev77.com/index.html
test.getfeewise.localhost {
rewrite * /blondev77.com{uri}
reverse_proxy {
to http://s3.us-east-2.amazonaws.com
header_up Host {upstream_hostport} # Done to keep AWS happy https://caddyserver.com/docs/caddyfile/directives/reverse_proxy#header_up
}
}
## The Easier stuff
uk.papi.getfeewise.localhost {
reverse_proxy localhost:8080
}
us.papi.getfeewise.localhost {
reverse_proxy localhost:8080
}
dashboard.getfeewise.localhost {
handle_path /us/* {
# reverse_proxy localhost:8081
file_server browse {
index us_dashboard.html
}
}
handle_path /uk/* {
file_server browse {
index uk_dashboard.html
}
}
}
# We'd want to look at https://caddyserver.com/docs/caddyfile/patterns#single-page-apps-spas
# to ensure we're actually capturing this but simple demo
# If we secure our buckets... well, https://github.com/mohammed90/caddy-aws-transport fun!
us.getfeewise.localhost {
file_server browse {
index us_customer.html
}
}
uk.getfeewise.localhost {
file_server browse {
index uk_customer.html
}
}
@17twenty
Copy link
Author

CEL matchers - https://caddyserver.com/docs/caddyfile/concepts#tokens-and-quotes

Any CEL (Common Expression Language) expression that returns true or false.

Caddy placeholders (or Caddyfile shorthands) may be used in these CEL expressions, as they are preprocessed and converted to regular CEL function calls before being interpreted by the CEL environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment