Skip to content

Instantly share code, notes, and snippets.

@1ma
Last active August 25, 2024 10:23
Show Gist options
  • Save 1ma/2c41d18a2add55378beb40155ecae5db to your computer and use it in GitHub Desktop.
Save 1ma/2c41d18a2add55378beb40155ecae5db to your computer and use it in GitHub Desktop.
Caddy Mempool config Goodenough™
:80 {
root /var/www/mempool/browser
handle /api/v1/* {
reverse_proxy 127.0.0.1:8999
}
handle /api/* {
uri replace /api/ /api/v1/
reverse_proxy 127.0.0.1:8999
}
handle {
map {header.accept-language} {header_lang} {
default "en-US"
~^ar "ar"
~^cs "cs"
~^da "da"
~^de "de"
~^en "en-US"
~^es "es"
~^fa "fa"
~^fi "fi"
~^fr "fr"
~^he "he"
~^hi "hi"
~^hr "hr"
~^hu "hu"
~^it "it"
~^ja "ja"
~^ka "ka"
~^ko "ko"
~^lt "lt"
~^mk "mk"
~^nb "nb"
~^ne "ne"
~^nl "nl"
~^pl "pl"
~^pt "pt"
~^ro "ro"
~^ru "ru"
~^sl "sl"
~^sv "sv"
~^th "th"
~^tr "tr"
~^uk "uk"
~^vi "vi"
~^zh "zh"
}
map {cookie.lang} {lang} {
default {header_lang}
ar "ar"
cs "cs"
da "da"
de "de"
en "en-US"
es "es"
fa "fa"
fi "fi"
fr "fr"
he "he"
hi "hi"
hr "hr"
hu "hu"
it "it"
ja "ja"
ka "ka"
ko "ko"
lt "lt"
mk "mk"
nb "nb"
ne "ne"
nl "nl"
pl "pl"
pt "pt"
ro "ro"
ru "ru"
sl "sl"
sv "sv"
th "th"
tr "tr"
uk "uk"
vi "vi"
zh "zh"
}
header {
Cache-Control "public, no-transform, max-age=1800"
Vary "Accept-Language, Cookie"
}
@lang-override path_regexp ^/([a-z]{2})/
handle @lang-override {
try_files {path} /{re.lang-override.1}/index.html /en-US{path} /en-US/index.html
}
handle {
try_files {path} /{lang}{path} /en-US{path} /{lang}/index.html /en-US/index.html
}
file_server
}
}
@1ma
Copy link
Author

1ma commented Aug 25, 2024

L'expressió regular de la revisió 3 era bastant infumable i pesada de mantenir.

Ara matcheja qualsevol prefix de 2 lletres minúscules, i si l'idioma no existeix prova 2 fallbacks més del segon try_files fins a arribar a /en-US/index.html en última instància.

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