Path handling issue using the map directive

That was tricky! I’m still mulling it over. One thing I’m beginning to appreciate, caddy adapt --pretty provides a level of detail that is hidden from view in the Caddyfile.

So, here is the final, working transformation of that Caddy block excerpt. It’s a lot more flexible than the original, but requires a greater depth of understanding to build.

udance.com.au www.udance.com.au {

  encode gzip
  import tlsdns
  import logging udance
  import authproxy /phpmyadmin*

  map {path} {backend} {online} {

#   PATH                BACKEND          ONLINE
#---------------------------------------------------------------
    ~^/tautulli.*       10.1.1.26:8181   yes
    ~^/transmission.*   10.1.1.28:9091   yes
    ~^/.*               10.1.1.55:80     yes
  }

  @offline expression `{online} == "no"`
  handle @offline {
    # Do whatever e.g. respond/redir 
  }

  reverse_proxy {backend}
}
3 Likes