mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-29 20:31:56 +08:00
Feat: CORS / Test: site/config route
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"github.com/HFO4/cloudreve/middleware"
|
||||
"github.com/HFO4/cloudreve/pkg/conf"
|
||||
"github.com/HFO4/cloudreve/routers/controllers"
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@@ -16,6 +17,14 @@ func InitRouter() *gin.Engine {
|
||||
*/
|
||||
r.Use(middleware.Session(conf.SystemConfig.SessionSecret))
|
||||
|
||||
// CORS TODO: 根据配置文件来
|
||||
r.Use(cors.New(cors.Config{
|
||||
AllowOrigins: []string{"http://localhost:3000"},
|
||||
AllowMethods: []string{"PUT", "POST", "GET", "OPTIONS"},
|
||||
AllowHeaders: []string{"X-PINGOTHER", "Content-Type"},
|
||||
AllowCredentials: true,
|
||||
}))
|
||||
|
||||
// 测试模式加入Mock助手中间件
|
||||
if gin.Mode() == gin.TestMode {
|
||||
r.Use(middleware.MockHelper())
|
||||
|
||||
Reference in New Issue
Block a user