aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--http_error_page.go12
-rw-r--r--http_server.go15
-rw-r--r--static/style.css11
-rw-r--r--templates/404.tmpl24
4 files changed, 55 insertions, 7 deletions
diff --git a/http_error_page.go b/http_error_page.go
new file mode 100644
index 0000000..2dd1f4f
--- /dev/null
+++ b/http_error_page.go
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// SPDX-FileContributor: Runxi Yu <https://runxiyu.org>
+
+package main
+
+import (
+ "net/http"
+)
+
+func errorPage404(w http.ResponseWriter, params map[string]any) {
+ _ = templates.ExecuteTemplate(w, "404", params)
+}
diff --git a/http_server.go b/http_server.go
index 35b3ca5..c883cdf 100644
--- a/http_server.go
+++ b/http_server.go
@@ -5,7 +5,6 @@ package main
import (
"errors"
- "fmt"
"net/http"
"strconv"
"strings"
@@ -58,7 +57,7 @@ func (router *forgeHTTPRouter) ServeHTTP(w http.ResponseWriter, r *http.Request)
if segments[0] == ":" {
if len(segments) < 2 {
- http.Error(w, "Blank system endpoint", http.StatusNotFound)
+ errorPage404(w, params)
return
} else if len(segments) == 2 && redirectDir(w, r) {
return
@@ -86,7 +85,7 @@ func (router *forgeHTTPRouter) ServeHTTP(w http.ResponseWriter, r *http.Request)
httpHandleGC(w, r, params)
return
default:
- http.Error(w, fmt.Sprintf("Unknown system module type: %s", segments[1]), http.StatusNotFound)
+ errorPage404(w, params)
return
}
}
@@ -119,10 +118,10 @@ func (router *forgeHTTPRouter) ServeHTTP(w http.ResponseWriter, r *http.Request)
}
httpHandleGroupIndex(w, r, params)
case len(segments) == sepIndex+1:
- http.Error(w, "Illegal path 1", http.StatusNotImplemented)
+ errorPage404(w, params)
return
case len(segments) == sepIndex+2:
- http.Error(w, "Illegal path 2", http.StatusNotImplemented)
+ errorPage404(w, params)
return
default:
moduleType = segments[sepIndex+1]
@@ -213,10 +212,12 @@ func (router *forgeHTTPRouter) ServeHTTP(w http.ResponseWriter, r *http.Request)
http.Error(w, "Too many parameters", http.StatusBadRequest)
}
default:
- http.Error(w, fmt.Sprintf("Unknown repo feature: %s", repoFeature), http.StatusNotFound)
+ errorPage404(w, params)
+ return
}
default:
- http.Error(w, fmt.Sprintf("Unknown module type: %s", moduleType), http.StatusNotFound)
+ errorPage404(w, params)
+ return
}
}
}
diff --git a/static/style.css b/static/style.css
index e5398ce..4f84182 100644
--- a/static/style.css
+++ b/static/style.css
@@ -408,3 +408,14 @@ td > ul {
margin-top: 0;
margin-bottom: 0;
}
+
+
+
+.complete-error-page {
+ font-family: 'Comic Sans MS', 'Chalkboard SE', 'Comic Neue', sans-serif;
+}
+
+.complete-error-page hr {
+ border: 0;
+ border-bottom: 1px dashed;
+}
diff --git a/templates/404.tmpl b/templates/404.tmpl
new file mode 100644
index 0000000..c994e1a
--- /dev/null
+++ b/templates/404.tmpl
@@ -0,0 +1,24 @@
+{{/*
+ SPDX-License-Identifier: AGPL-3.0-only
+ SPDX-FileContributor: Runxi Yu <https://runxiyu.org>
+*/}}
+{{- define "404" -}}
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ {{- template "head_common" . -}}
+ <title>404 Not Found &ndash; {{ .global.forge_title }}</title>
+ </head>
+ <body class="404">
+ {{- template "header" . -}}
+ <div class="padding-wrapper complete-error-page">
+ <h1>404 Not Found</h1>
+ <hr />
+ <address>Lindenii Forge</address>
+ </div>
+ <footer>
+ {{- template "footer" . -}}
+ </footer>
+ </body>
+</html>
+{{- end -}}