package route import ( "net/http" "path" "forge.cadoles.com/wpetit/gengitkan/internal/config" "forge.cadoles.com/wpetit/gengitkan/internal/middleware" "github.com/go-chi/chi" "gitlab.com/wpetit/goweb/middleware/container" "gitlab.com/wpetit/goweb/static" ) func Mount(r *chi.Mux, config *config.Config) { r.Group(func(r chi.Router) { r.Get("/callback", handleOAuth2Callback) // Authenticated routes r.Group(func(r chi.Router) { r.Use(middleware.Authenticate) r.Get("/logout", handleLogout) r.Get("/api/boards", serveBoards) r.Post("/api/boards", saveBoard) r.Delete("/api/boards/{boardID}", deleteBoard) r.Handle("/gitea/api/*", http.StripPrefix("/gitea", http.HandlerFunc(proxyAPIRequest))) r.Get("/*", static.Dir(config.HTTP.PublicDir, "", html5PushStateHandler)) }) }) } func html5PushStateHandler(w http.ResponseWriter, r *http.Request) { ctn := container.Must(r.Context()) conf := config.Must(ctn) indexFile := path.Join(conf.HTTP.PublicDir, "index.html") http.ServeFile(w, r, indexFile) }