From 1f55ecb6491f46aceab6c7af9aa8de4962ca2aae Mon Sep 17 00:00:00 2001 From: Harry-zklcdc Date: Sun, 16 Feb 2025 23:53:14 +0800 Subject: [PATCH] =?UTF-8?q?[Fix]=20=F0=9F=90=9B=20Cors=20Error=20at=20Fron?= =?UTF-8?q?tEnd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/index/cors.go | 12 ++++++++++++ routers/index/routers.go | 1 + 2 files changed, 13 insertions(+) create mode 100644 routers/index/cors.go diff --git a/routers/index/cors.go b/routers/index/cors.go new file mode 100644 index 0000000..4ca422c --- /dev/null +++ b/routers/index/cors.go @@ -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() +} diff --git a/routers/index/routers.go b/routers/index/routers.go index 0dfa714..a72818e 100644 --- a/routers/index/routers.go +++ b/routers/index/routers.go @@ -5,6 +5,7 @@ import ( ) func InitIndex(app *iris.Application) { + app.Use(cors) app.HandleDir("/", GetWebFS(), iris.DirOptions{ IndexName: "/index.html", Compress: true,