Fix acme challenges not taking priority over origins

This commit is contained in:
Brian Picciano 2023-05-20 15:24:32 +02:00
parent 7d4f754eec
commit 08b35f6b21

View File

@ -330,17 +330,11 @@ where
}
.and_then(|h| domain::Name::from_str(h).ok());
if let Some(domain) = maybe_host {
return svc.serve_origin(domain, req.uri().path());
}
let method = req.method();
let path = req.uri().path();
if method == Method::GET && path.starts_with("/static/") {
return svc.render(200, path, ());
}
// Serving acme challenges always takes priority. We serve them from the same store no matter
// the domain, presumably they are cryptographically random enough that it doesn't matter.
if method == Method::GET && path.starts_with("/.well-known/acme-challenge/") {
let token = path.trim_start_matches("/.well-known/acme-challenge/");
@ -356,6 +350,17 @@ where
}
}
// If a managed domain was given then serve that from its origin
if let Some(domain) = maybe_host {
return svc.serve_origin(domain, req.uri().path());
}
// Serve main domiply site
if method == Method::GET && path.starts_with("/static/") {
return svc.render(200, path, ());
}
match (method, path) {
(&Method::GET, "/") | (&Method::GET, "/index.html") => svc.render_page("/index.html", ()),
(&Method::GET, "/domain.html") => {