indiescrobble/server/router.go

55 lines
1.2 KiB
Go
Raw Normal View History

package server
import (
"git.jamesravey.me/ravenscroftj/indiescrobble/config"
"git.jamesravey.me/ravenscroftj/indiescrobble/controllers"
"git.jamesravey.me/ravenscroftj/indiescrobble/middlewares"
"github.com/gin-gonic/gin"
)
func NewRouter() *gin.Engine {
router := gin.New()
router.Use(gin.Logger())
router.Use(gin.Recovery())
config := config.GetConfig()
health := new(controllers.HealthController)
2022-02-05 16:24:07 +00:00
iam := controllers.NewIndieAuthManager()
router.GET("/health", health.Status)
router.Use(middlewares.AuthMiddleware(false))
2022-02-05 16:24:07 +00:00
router.GET("/", controllers.Index)
router.Static("/static", config.GetString("server.static_path"))
// add auth endpoints
2022-02-05 16:24:07 +00:00
router.POST("/indieauth", iam.IndieAuthLoginPost)
router.GET("/auth", iam.LoginCallbackGet)
router.GET("/logout", iam.Logout)
authed := router.Use(middlewares.AuthMiddleware(true))
// add scrobble endpoints
authed.GET("/scrobble", controllers.Scrobble)
authed.POST("/scrobble/preview", controllers.PreviewScrobble)
2022-02-05 16:24:07 +00:00
// v1 := router.Group("v1")
// {
// userGroup := v1.Group("user")
// {
// user := new(controllers.UserController)
// userGroup.GET("/:id", user.Retrieve)
// }
// }
return router
}