Feat: CORS / Test: site/config route

This commit is contained in:
HFO4
2019-11-23 15:09:46 +08:00
parent 370a1a0c9f
commit 948059ec1c
8 changed files with 100 additions and 61 deletions

View File

@@ -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())