adjust cors

This commit is contained in:
engigu
2024-01-02 14:18:23 +08:00
parent 4af4931648
commit 5d5cdf5bc8
2 changed files with 13 additions and 17 deletions
+1 -12
View File
@@ -40,20 +40,9 @@ jobs:
working-directory: web/
- name: Check build static
run: ls -la
run: ls dist/ -la
working-directory: web/
# goreleaser:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# with:
# fetch-depth: 0
# - run: git fetch --force --tags
# - uses: actions/setup-go@v3
# with:
# go-version: '>=1.20.2'
# cache: true
# More assembly might be required: Docker logins, GPG, etc. It all depends
# on your needs.
- uses: goreleaser/goreleaser-action@v4
+12 -5
View File
@@ -11,11 +11,19 @@ import (
"net/http"
)
// 打包集成静态资源
func ServerStaticHtml(r *gin.Engine, f embed.FS) {
// AppendCors 添加是否跨域(debug模式开启)
func AppendCors(r *gin.Engine) {
if setting.ServerSetting.RunMode == "debug" {
r.Use(middleware.Cors())
}
}
// ServerStaticHtml 启用返回打包的静态文件
func AppendServerStaticHtml(r *gin.Engine, f embed.FS) {
if setting.ServerSetting.EmbedHtml == "disable" {
return
}
assets, _ := fs.Sub(f, "web/dist/assets")
dist, _ := fs.Sub(f, "web/dist")
@@ -31,10 +39,9 @@ func InitRouter(f embed.FS) *gin.Engine {
r := gin.New()
r.Use(middleware.LogMiddleware())
r.Use(gin.Recovery())
r.Use(middleware.Cors())
// 打包
ServerStaticHtml(r, f)
AppendCors(r)
AppendServerStaticHtml(r, f)
r.POST("/auth", api.GetAuth)
apiv1 := r.Group("/api/v1")