2019-11-28 11:50:51 +01:00
|
|
|
package route
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"path"
|
|
|
|
|
2020-04-30 10:32:12 +02:00
|
|
|
"forge.cadoles.com/wpetit/gengitkan/internal/config"
|
|
|
|
"forge.cadoles.com/wpetit/gengitkan/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)
|
2019-12-13 13:28:59 +01:00
|
|
|
r.Delete("/api/boards/{boardID}", deleteBoard)
|
2019-12-01 22:12:13 +01:00
|
|
|
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)
|
|
|
|
}
|