// for each redirect listener, see if there's already a
// for each redirect listener, see if there's already a
// server configured to listen on that exact address; if so,
// server configured to listen on that exact address; if so,
// simply add the redirect route to the end of its route
// insert the redirect route to the end of its route list
// list; otherwise, we'll create a new server for all the
// after any other routes with host matchers; otherwise,
// listener addresses that are unused and serve the
// we'll create a new server for all the listener addresses
// remaining redirects from it
// that are unused and serve the remaining redirects from it
forsrvName,srv:=rangeapp.Servers{
for_,srv:=rangeapp.Servers{
ifsrv.hasListenerAddress(redirServerAddr){
ifsrv.hasListenerAddress(redirServerAddr){
// user has configured a server for the same address
// find the index of the route after the last route with a host
// that the redirect runs from; simply append our
// matcher, then insert the redirects there, but before any
// redirect route to the existing routes, with a
// user-defined catch-all routes
// caveat that their config might override ours
// see https://github.com/caddyserver/caddy/issues/3212
app.logger.Warn("user server is listening on same interface as automatic HTTP->HTTPS redirects; user-configured routes might override these redirects",