Hi, currently I am using the geoip plugin to check the user’s country.
And I’m trying to do if/else in Caddy file, I’ve been searching for quite some time, but I still don’t have a definite solution. I want 2 conditions
if {geoip.country_code} == "US" {
reverse_proxy localhost:3000
}else if {geoip.country_code} == "HK"{
reverse_proxy localhost:3001
}
I’m not sure if caddy supports such condition? If anyone comes across this thread, please help me out a bit. I’m really grateful
Caddy will sort handlers with a matcher higher than those without, so you don’t need the condition for the “else” case, and reverse_proxy is a terminal handler (by default) so it will be the last thing to run in the middleware chain:
But in general, I’d recommend using handle blocks to implement mutual exclusivity, especially if you’re not simply using a single directive of the same kind, in either case.