summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroerick <sweeney@roerick.me>2025-10-19 16:30:28 -0600
committerroerick <sweeney@roerick.me>2025-10-19 16:30:28 -0600
commit0b76fa014a49cf58278b8e6cf81a0b285dc5773a (patch)
tree3128e3371fcfcc61dbcfc56b0a2f9ef5bd7999f3
parent56b77ad18c90e47299c46d6f0fde8abe3ff6d16d (diff)
reading md works
-rw-r--r--main.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/main.go b/main.go
index e39e8c5..b65e877 100644
--- a/main.go
+++ b/main.go
@@ -8,6 +8,7 @@ import (
"wyo.town/netzah/handlers"
"wyo.town/netzah/session"
"wyo.town/netzah/middleware"
+ "wyo.town/netzah/blog"
"github.com/gorilla/mux"
"gorm.io/driver/postgres"
@@ -25,12 +26,18 @@ func init() {
-
+func loggingMiddleware(next http.Handler) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ log.Printf("Incoming request: %s %s", r.Method, r.URL.Path)
+ next.ServeHTTP(w, r)
+ })
+}
func main() {
session.Init()
mux := mux.NewRouter()
mux.Use(session.Manager.LoadAndSave)
+ mux.Use(loggingMiddleware)
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
@@ -40,22 +47,16 @@ func main() {
mux.HandleFunc("/blogs", handlers.CreateBlog).Methods(http.MethodGet)
mux.HandleFunc("/blogs", handlers.StoreBlog).Methods(http.MethodPost)
mux.HandleFunc("/blogs/{id}", handlers.GetBlog).Methods(http.MethodGet)
-
- mux.HandleFunc("GET /posts/{slug}", func(w http.ResponseWriter, r *http.Request) {
- slug := r.PathValue("slug")
- fmt.Fprintf(w, "Post: %s", slug)
- })
+ mux.HandleFunc("/posts/{slug}", blog.PostHandler(blog.FileReader{}))
mux.HandleFunc("/login", handlers.LoginGET)
mux.HandleFunc("/login/submit", handlers.LoginPOST)
- // Logout (POST is recommended; allow GET only if you must)
mux.HandleFunc("/logout", handlers.LogoutPOST)
// mux.HandleFunc("/blogs/{id}", handlers.UpdateBlog).Methods(http.MethodPut)
// mux.HandleFunc("/blogs/{id}", handlers.DeleteBlog).Methods(http.MethodDelete)
- // Example protected route (SCS must already be on the chain)
mux.Handle("/whoami", middleware.RequireAuth(http.HandlerFunc(handlers.Dashboard)))
log.Println("Starting server on :8090")