2024-10-07 01:21:13 +00:00
|
|
|
package src
|
|
|
|
|
|
|
|
import (
|
|
|
|
"acide/src/modules/auth"
|
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"))
|
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|