alist/server/router.go

35 lines
969 B
Go
Raw Normal View History

2022-06-06 14:08:39 +00:00
package server
2022-06-25 12:38:02 +00:00
import (
2022-06-25 13:34:44 +00:00
"github.com/alist-org/alist/v3/internal/conf"
2022-06-26 11:10:14 +00:00
"github.com/alist-org/alist/v3/server/common"
2022-06-26 11:20:19 +00:00
"github.com/alist-org/alist/v3/server/controllers"
2022-06-26 11:10:14 +00:00
"github.com/alist-org/alist/v3/server/middlewares"
2022-06-25 12:38:02 +00:00
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
func Init(r *gin.Engine) {
2022-06-25 13:34:44 +00:00
common.SecretKey = []byte(conf.Conf.JwtSecret)
2022-06-25 12:38:02 +00:00
Cors(r)
2022-06-25 13:34:44 +00:00
2022-06-26 08:39:02 +00:00
api := r.Group("/api", middlewares.Auth)
2022-06-26 11:20:19 +00:00
api.POST("/auth/login", controllers.Login)
api.GET("/auth/current", controllers.CurrentUser)
2022-06-26 11:09:28 +00:00
admin := api.Group("/admin", middlewares.AuthAdmin)
meta := admin.Group("/meta")
2022-06-26 11:20:19 +00:00
meta.GET("/list", controllers.ListMetas)
meta.POST("/create", controllers.CreateMeta)
meta.POST("/update", controllers.UpdateMeta)
meta.POST("/delete", controllers.DeleteMeta)
2022-06-25 12:38:02 +00:00
}
func Cors(r *gin.Engine) {
config := cors.DefaultConfig()
config.AllowAllOrigins = true
config.AllowHeaders = append(config.AllowHeaders, "Authorization", "range")
r.Use(cors.New(config))
}