[Fix] 🐛 Cors Error at FrontEnd

This commit is contained in:
Harry-zklcdc 2025-02-16 23:53:14 +08:00
parent 87995f0572
commit 1f55ecb649
2 changed files with 13 additions and 0 deletions

12
routers/index/cors.go Normal file
View File

@ -0,0 +1,12 @@
package index
import "github.com/kataras/iris/v12"
func cors(ctx iris.Context) {
ctx.Header("Access-Control-Allow-Origin", "*")
ctx.Header("Access-Control-Allow-Methods", "GET")
ctx.Header("Access-Control-Allow-Headers", "Content-Type, Authorization")
ctx.Header("Access-Control-Max-Age", "86400")
ctx.Header("Access-Control-Allow-Credentials", "true")
ctx.Next()
}

View File

@ -5,6 +5,7 @@ import (
)
func InitIndex(app *iris.Application) {
app.Use(cors)
app.HandleDir("/", GetWebFS(), iris.DirOptions{
IndexName: "/index.html",
Compress: true,