fix: 将开发和生产环境进行区分
This commit is contained in:
@@ -16,17 +16,34 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func SetupRouter() *gin.Engine {
|
||||
var (
|
||||
AllowOrigins []string
|
||||
AllowMethods []string
|
||||
AllowHeaders []string
|
||||
)
|
||||
|
||||
func init() {
|
||||
if conf.Mode != gin.ReleaseMode {
|
||||
AllowOrigins = []string{"*"}
|
||||
AllowMethods = []string{"*"}
|
||||
AllowHeaders = []string{"*"}
|
||||
gin.SetMode(gin.DebugMode)
|
||||
} else {
|
||||
AllowOrigins = []string{"*.kmux.cn"}
|
||||
AllowMethods = []string{"GET", "POST", "PUT", "DELETE", "PATCH"}
|
||||
AllowHeaders = []string{"X-Session-Id"}
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
}
|
||||
|
||||
func SetupRouter() *gin.Engine {
|
||||
|
||||
r := gin.Default()
|
||||
|
||||
r.Use(cors.New(cors.Config{
|
||||
AllowOrigins: []string{"*.kmux.cn*"},
|
||||
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "PATCH"},
|
||||
AllowHeaders: []string{"*", "X-Session-Id"},
|
||||
AllowOrigins: AllowOrigins,
|
||||
AllowMethods: AllowMethods,
|
||||
AllowHeaders: AllowHeaders,
|
||||
ExposeHeaders: []string{"Content-Length"},
|
||||
AllowCredentials: true,
|
||||
MaxAge: 12 * time.Hour,
|
||||
@@ -56,6 +73,8 @@ func SetupRouter() *gin.Engine {
|
||||
v2 := api.Group("/v2", sessionMiddleware)
|
||||
{
|
||||
v2.POST("/logout", wkHandler.Logout)
|
||||
v2.POST("/userinfo", wkHandler.UserInfo)
|
||||
v2.POST("/course", wkHandler.Course)
|
||||
v2.POST("/study", wkHandler.Study)
|
||||
v2.POST("/record", wkHandler.AllRecord)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user