magmise/api/main.go

28 lines
602 B
Go
Raw Normal View History

2022-09-09 06:10:34 +00:00
package main
import (
"magmise/controllers"
"magmise/models"
"net/http"
2022-09-10 13:22:07 +00:00
"os"
2022-09-09 06:10:34 +00:00
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
2022-09-10 13:22:07 +00:00
"github.com/gorilla/csrf"
2022-09-09 06:10:34 +00:00
)
func main() {
2022-09-10 13:21:20 +00:00
models.Store()
2022-09-09 06:10:34 +00:00
models.Init()
var user controllers.User
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Handle("/*", http.FileServer(http.Dir("/api/www")))
r.Get("/user/{username}", user.Get)
r.Post("/user/{username}", user.Create)
2022-09-10 13:21:20 +00:00
r.Post("/login", controllers.Login)
r.Post("/logout", controllers.Logout)
2022-09-10 13:22:07 +00:00
CSRF := csrf.Protect([]byte(os.Getenv("CSRFKEY")))
http.ListenAndServe(":8080", CSRF(r))
2022-09-09 06:10:34 +00:00
}