music-to-go/src/routes.go

45 lines
1.0 KiB
Go
Raw Normal View History

2024-10-07 01:21:13 +00:00
package src
import (
"acide/src/modules/auth"
2024-10-08 12:55:00 +00:00
"acide/src/modules/covers"
2024-10-08 00:37:20 +00:00
"acide/src/modules/index"
2024-10-07 01:21:13 +00:00
"net/http"
"os"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
)
2024-10-08 00:37:20 +00:00
var dev = os.Getenv("APP_ENV") == "dev"
2024-10-07 01:21:13 +00:00
// Sets up the Echo server, and registers all routes and sub routes
func (s *Server) RegisterRoutes() http.Handler {
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
// e.Use(middleware.CSRF())
// Static files
staticFilesFolder := disableCacheInDevMode(http.StripPrefix("/public",
http.FileServer(http.Dir("public"))))
e.GET("/public/*", echo.WrapHandler(staticFilesFolder))
2024-10-08 00:37:20 +00:00
// NOTE: Register subroutes here
index.SetupRoutes(e.Group(""))
2024-10-07 01:21:13 +00:00
auth.SetupRoutes(e.Group("/auth"))
2024-10-08 12:55:00 +00:00
covers.Setup(e.Group("/covers"))
2024-10-07 01:21:13 +00:00
return e
}
func disableCacheInDevMode(next http.Handler) http.Handler {
if !dev {
return next
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-store")
next.ServeHTTP(w, r)
})
}