aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/data.go4
-rw-r--r--backend/home.go15
-rw-r--r--backend/logs.go2
-rw-r--r--backend/router.go2
-rw-r--r--backend/templates/404.html15
5 files changed, 34 insertions, 4 deletions
diff --git a/backend/data.go b/backend/data.go
index cc61941..fe5aa96 100644
--- a/backend/data.go
+++ b/backend/data.go
@@ -30,6 +30,10 @@ type data struct {
Quote string
}
+func (d *data) SetData(data *data) {
+ *d = *data
+}
+
func (d *data) handleGeneric(w http.ResponseWriter, r *http.Request, name string, custom dataUsable) {
cfg := r.Context().Value(configKey).(*Config)
if d.Domain == "" {
diff --git a/backend/home.go b/backend/home.go
index b2a6dfa..69bb156 100644
--- a/backend/home.go
+++ b/backend/home.go
@@ -41,6 +41,17 @@ func HandleHome(r *chi.Mux) {
})
}
+func Handle404(r *chi.Mux) {
+ r.NotFound(notFound)
+}
+
+func notFound(w http.ResponseWriter, r *http.Request) {
+ d := new(data)
+ d.title = "404"
+ w.WriteHeader(http.StatusNotFound)
+ d.handleGeneric(w, r, "404", d)
+}
+
type rootData struct {
*data
Content template.HTML
@@ -71,7 +82,7 @@ func handleGenericRoot(w http.ResponseWriter, r *http.Request, name string) {
b, err := os.ReadFile(path)
if err != nil {
if os.IsNotExist(err) {
- http.NotFoundHandler().ServeHTTP(w, r)
+ notFound(w, r)
return
}
panic(err)
@@ -109,7 +120,7 @@ func handleGenericLogsDisplay(w http.ResponseWriter, r *http.Request) *homeData
d.CurrentPage = page
d.PagesNumber = len(sortedLogs)/maxLogsPerPage + 1
if d.PagesNumber < page {
- http.NotFoundHandler().ServeHTTP(w, r)
+ notFound(w, r)
return nil
}
d.Logs = sortedLogs[(page-1)*maxLogsPerPage : min(page*maxLogsPerPage, len(sortedLogs))]
diff --git a/backend/logs.go b/backend/logs.go
index c663ffb..3b5bd70 100644
--- a/backend/logs.go
+++ b/backend/logs.go
@@ -137,7 +137,7 @@ func handleLog(w http.ResponseWriter, r *http.Request) {
d = new(logData)
d.data = new(data)
if ok = parseLog(d, path, slug); !ok {
- http.NotFoundHandler().ServeHTTP(w, r)
+ notFound(w, r)
return
}
}
diff --git a/backend/router.go b/backend/router.go
index 22c77a4..adc28fc 100644
--- a/backend/router.go
+++ b/backend/router.go
@@ -16,7 +16,7 @@ import (
)
const (
- Version = "0.1.0"
+ Version = "0.2.0"
configKey = "config"
isUpdateKey = "is_update"
)
diff --git a/backend/templates/404.html b/backend/templates/404.html
new file mode 100644
index 0000000..0655652
--- /dev/null
+++ b/backend/templates/404.html
@@ -0,0 +1,15 @@
+{{ define "body" }}
+<main id="content">
+ <h1>Oh non, je crois que tu t'es perdu :(</h1>
+ <p>
+ Tu as des liens en haut pour retrouver ton chemin :3
+ </p>
+ <p>
+ Si tu penses que c'est un bug, hésite pas à ouvrir une issue sur
+ <a href="https://github.com/anhgelus/small-web/issues">GitHub</a> :D
+ </p>
+ <p>
+ (enfin, sauf si tu as un compte sur ma forge, mais ça m'étonnerait...)
+ </p>
+</main>
+{{ end }} \ No newline at end of file