package main

import (
	"magmise/controllers"
	"magmise/models"
	"net/http"
	"os"

	"github.com/go-chi/chi/v5"
	"github.com/go-chi/chi/v5/middleware"
	"github.com/gorilla/csrf"
)

func main() {
	models.Store()
	models.Init()
	var user controllers.User
	r := chi.NewRouter()
	r.Use(middleware.Logger)
	r.Handle("/*", http.FileServer(http.Dir("/api/www")))
	r.Get("/api/user/{username}", user.Get)
	r.Post("/api/user/{username}", user.Create)
	r.Post("/api/login", controllers.Login)
	r.Post("/api/logout", controllers.Logout)
	CSRF := csrf.Protect([]byte(os.Getenv("CSRFKEY")))
	http.ListenAndServe(":8080", CSRF(r))
}