restructuring, config and readme
This commit is contained in:
32
backend/internal/initialize/inject.go
Normal file
32
backend/internal/initialize/inject.go
Normal file
@ -0,0 +1,32 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.schreifuchs.ch/schreifuchs/ng-blog/backend/internal/auth"
|
||||
"git.schreifuchs.ch/schreifuchs/ng-blog/backend/internal/blog"
|
||||
"git.schreifuchs.ch/schreifuchs/ng-blog/backend/internal/config"
|
||||
"git.schreifuchs.ch/schreifuchs/ng-blog/backend/internal/model"
|
||||
"git.schreifuchs.ch/schreifuchs/ng-blog/backend/pkg/cors"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func CreateMux(cfg *config.Config) (r *mux.Router) {
|
||||
db := model.Init()
|
||||
blg := blog.New(db)
|
||||
auth := auth.New(&cfg.Auth, db)
|
||||
|
||||
r = mux.NewRouter()
|
||||
r.Use(cors.HandlerForOrigin("*"))
|
||||
r.HandleFunc("/login", auth.Login).Methods("POST")
|
||||
r.Handle("/posts", auth.Authenticated(blg.SavePost)).Methods("POST")
|
||||
r.Handle("/posts", auth.Authenticated(blg.SavePost)).Methods("PUT")
|
||||
r.Handle("/posts/{postID}", auth.Authenticated(blg.DeletePost)).Methods("DELETE")
|
||||
r.Handle("/posts", http.HandlerFunc(blg.GetAllPosts)).Methods("GET")
|
||||
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)
|
||||
})
|
||||
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user