2019-11-28 11:50:51 +01:00
|
|
|
package route
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"path"
|
|
|
|
|
2019-11-28 12:13:01 +01:00
|
|
|
"forge.cadoles.com/wpetit/gitea-kan/internal/config"
|
|
|
|
"forge.cadoles.com/wpetit/gitea-kan/internal/middleware"
|
2019-11-28 11:50:51 +01:00
|
|
|
"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)
|
2019-12-01 22:12:13 +01:00
|
|
|
r.Get("/api/boards", serveBoards)
|
|
|
|
r.Post("/api/boards", saveBoard)
|
|
|
|
r.Handle("/gitea/api/*", http.StripPrefix("/gitea", http.HandlerFunc(proxyAPIRequest)))
|
2019-11-28 11:50:51 +01:00
|
|
|
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)
|
|
|
|
}
|