WiiCITMS/routers/router.go

43 lines
1.2 KiB
Go
Raw Permalink Normal View History

2025-11-07 14:14:34 +08:00
package routers
import (
v1controllers "WiiCITMS/controllers/v1"
"github.com/gin-gonic/gin"
)
// Cors 跨域设置
func Cors() gin.HandlerFunc {
return func(c *gin.Context) {
method := c.Request.Method
origin := c.Request.Header.Get("Origin")
if origin != "" {
c.Header("Access-Control-Allow-Origin", "*")
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE")
c.Header("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, X-User-Agent, X-User-Id, X-Device-Id")
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Cache-Control, Content-Language, Content-Type")
c.Header("Access-Control-Allow-Credentials", "true")
}
if method == "OPTIONS" {
c.AbortWithStatus(200)
}
c.Next()
}
}
func RegisterRouter() *gin.Engine {
router := gin.Default()
router.Use(Cors())
router.Static("/userfiles", "./userfiles")
{
v1 := router.Group("/citms/api/v1")
v1.GET("/version", v1controllers.VersionInfo)
// authenticate := v1.Group("/hr")
// {
// authenticate.POST("/login", v1controllers.Authenticate)
// }
}
return router
}