all repos — homestead @ ee2bafee7f4d26c681bfbe9af1c662698bc91c73

Code for my website

server: 404 if host not recognised

Alan Pearce
commit

ee2bafee7f4d26c681bfbe9af1c662698bc91c73

parent

7a439ecb24c4c6f3e3a5b243a5b6059da1601870

1 file changed, 3 insertions(+), 1 deletion(-)

jump to
M internal/server/server.gointernal/server/server.go
@@ -194,10 +194,12 @@ if slices.Contains(config.Domains, r.Host) {
path, _ := website.CanonicalisePath(r.URL.Path) newURL := config.BaseURL.JoinPath(path) http.Redirect(w, r, newURL.String(), http.StatusMovedPermanently) - } else { + } else if re.MatchString(r.Host) { url := config.BaseURL url.Host = re.ReplaceAllString(r.Host, replace) http.Redirect(w, r, url.String(), http.StatusTemporaryRedirect) + } else { + http.NotFound(w, r) } }) } else {