diff options
| author | roerick <sweeney@roerick.me> | 2025-10-19 16:30:28 -0600 |
|---|---|---|
| committer | roerick <sweeney@roerick.me> | 2025-10-19 16:30:28 -0600 |
| commit | 0b76fa014a49cf58278b8e6cf81a0b285dc5773a (patch) | |
| tree | 3128e3371fcfcc61dbcfc56b0a2f9ef5bd7999f3 /main.go | |
| parent | 56b77ad18c90e47299c46d6f0fde8abe3ff6d16d (diff) | |
reading md works
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 17 |
1 files changed, 9 insertions, 8 deletions
@@ -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") |
