started with post editor

This commit is contained in:
u80864958
2025-04-11 15:38:04 +02:00
parent fb2d784421
commit efe902639e
29 changed files with 387 additions and 16 deletions

View File

@ -28,11 +28,13 @@ func main() {
db := model.Init()
blg := blog.New(db)
r := mux.NewRouter()
r.Use(cors.HandlerForOrigin("*"))
r.Handle("/login", auth.Login(user, password, []byte(secret))).Methods("POST")
r.Handle("/posts", auth.Authenticated([]byte(secret))(blg.CreatePost)).Methods("POST")
r.Handle("/posts", http.HandlerFunc(blg.GetAllPosts)).Methods("GET")
r.Use(cors.HandlerForOrigin("*"))
r.Methods("OPTIONS").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// The CORS middleware should set up the headers for you
w.WriteHeader(http.StatusNoContent)
})
http.ListenAndServe(":8080", r)
}