diff --git a/README.md b/README.md index 8103585..9665ec1 100644 --- a/README.md +++ b/README.md @@ -26,4 +26,7 @@ data | ... +-- log.txt +-- readme.txt + +config ++-- config.txt ``` \ No newline at end of file diff --git a/TODO.md b/TODO.md index 3ffe4fc..f2ae5d9 100644 --- a/TODO.md +++ b/TODO.md @@ -5,8 +5,9 @@ List of things to add to this project * Add export feature * Add missing frontend pages -## Long-medium term -* *Go* dependency-less -* Improve (add?) logging, log to files +## Long-medium term considerations +* Improve logging, log to files * Make the CLI better -* Timezones? \ No newline at end of file +* Think about timezones +* Consider more secure auth methods +* *Go* dependency-less? <-- this is a terrible idea \ No newline at end of file diff --git a/auth.go b/auth.go index e18b002..881a15c 100644 --- a/auth.go +++ b/auth.go @@ -6,11 +6,11 @@ import ( "net/http" ) -// This middleware handles authentication & authorization for the app. +// BasicAuth is a middleware that handles authentication & authorization for the app. // It uses BasicAuth because I doubt there is a need for something sophisticated in a small hobby project // Originally taken from https://www.alexedwards.net/blog/basic-authentication-in-go (13.03.2024) // TODO: why did I have to convert Handler from HandlerFunc? -func basicAuth(next http.Handler) http.Handler { +func BasicAuth(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { username, password, ok := r.BasicAuth() if ok { diff --git a/go.mod b/go.mod index dd50501..c39d590 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,5 @@ module hibiscus -go 1.20 +go 1.22 require github.com/go-chi/chi/v5 v5.0.12 diff --git a/serve.go b/serve.go index 1ccc070..2670e36 100644 --- a/serve.go +++ b/serve.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" + "log" "net/http" "strconv" ) @@ -11,7 +12,7 @@ import ( func Serve() { r := chi.NewRouter() r.Use(middleware.Logger, middleware.CleanPath, middleware.StripSlashes) - r.Use(basicAuth) // TODO: ..duh! + r.Use(BasicAuth) // TODO: is this good enough? r.NotFound(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(404) http.ServeFile(w, r, "./pages/error/404.html") @@ -43,8 +44,8 @@ func Serve() { // Static files fs := http.FileServer(http.Dir("public")) - r.Handle("/public/*", http.StripPrefix("/public/", fs)) + r.Handle("/public/", http.StripPrefix("/public/", fs)) fmt.Println("Website working on port: ", Cfg.Port) - _ = http.ListenAndServe(":"+strconv.Itoa(Cfg.Port), r) + log.Fatal(http.ListenAndServe(":"+strconv.Itoa(Cfg.Port), r)) }