34 lines
908 B
Go
34 lines
908 B
Go
package route
|
|
|
|
import (
|
|
"net/http"
|
|
"path"
|
|
|
|
"forge.cadoles.com/wpetit/gitea-kan/config"
|
|
"forge.cadoles.com/wpetit/gitea-kan/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("/gitea/api/*", http.StripPrefix("/gitea", http.HandlerFunc(proxyAPIRequest)).ServeHTTP)
|
|
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)
|
|
}
|