Skip to content

Commit 62699af

Browse files
committed
Render 404 instead of redirecting to it
1 parent a9b2775 commit 62699af

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,26 @@ func main() {
5858
w.Write(data)
5959
})
6060

61+
// Helper to serve 404 page
62+
serve404 := func(w http.ResponseWriter) {
63+
data, _ := content.ReadFile("404.html")
64+
w.Header().Set("Content-Type", "text/html; charset=utf-8")
65+
w.WriteHeader(http.StatusNotFound)
66+
w.Write(data)
67+
}
68+
6169
// Serve generic error pages
6270
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
6371
path := strings.TrimPrefix(r.URL.Path, "/")
6472
if path == "" {
6573
// Default to 404
66-
http.Redirect(w, r, "/404", http.StatusFound)
74+
serve404(w)
6775
return
6876
}
6977

7078
code, err := strconv.Atoi(path)
7179
if err != nil || code < 100 || code > 599 {
72-
http.Redirect(w, r, "/404", http.StatusFound)
80+
serve404(w)
7381
return
7482
}
7583

0 commit comments

Comments
 (0)