This commit is contained in:
@ -19,9 +19,7 @@ func CreateMux(cfg *config.Config) (r *mux.Router) {
|
||||
r.Use(cors.HandlerForOrigin("*"))
|
||||
|
||||
app(r.PathPrefix("/api").Subrouter(), cfg)
|
||||
|
||||
frontend := web.Frontend
|
||||
r.PathPrefix("/").Handler(middlewares.AddPrefix("/dist/frontend/browser", http.FileServerFS(frontend)))
|
||||
frontend(r.PathPrefix("/"))
|
||||
|
||||
r.Methods("OPTIONS").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// The CORS middleware should set up the headers for you
|
||||
@ -31,15 +29,28 @@ func CreateMux(cfg *config.Config) (r *mux.Router) {
|
||||
return
|
||||
}
|
||||
|
||||
func frontend(r *mux.Route) {
|
||||
frontend := web.Frontend
|
||||
r.Handler(
|
||||
middlewares.AddPrefix("/dist/frontend/browser",
|
||||
middlewares.FallbackFile(
|
||||
frontend,
|
||||
"/dist/frontend/browser/index.html",
|
||||
http.FileServerFS(frontend),
|
||||
),
|
||||
))
|
||||
}
|
||||
|
||||
func app(r *mux.Router, cfg *config.Config) {
|
||||
db := model.Init()
|
||||
blg := posts.New(db)
|
||||
auth := auth.New(&cfg.Auth, db)
|
||||
|
||||
// auth
|
||||
r.HandleFunc("/login", auth.Login).Methods("POST")
|
||||
r.HandleFunc("/signup", auth.Signup).Methods("POST")
|
||||
r.Handle("/logout", auth.Authenticated(auth.Logout)).Methods("DELETE")
|
||||
r.HandleFunc("/auth/login", auth.Login).Methods("POST")
|
||||
r.HandleFunc("/auth/signup", auth.Signup).Methods("POST")
|
||||
r.Handle("/auth/password", auth.Authenticated(auth.ChangePassword)).Methods("PUT")
|
||||
r.Handle("/auth/logout", auth.Authenticated(auth.Logout)).Methods("DELETE")
|
||||
|
||||
// Posts
|
||||
r.Handle("/posts", auth.Authenticated(blg.SavePost, model.RoleUser, model.RoleAdmin)).Methods("POST")
|
||||
|
Reference in New Issue
Block a user