From fd8e397e162f80cedf37230cf03753f2d9dc2b18 Mon Sep 17 00:00:00 2001 From: plm Date: Wed, 15 Jan 2025 11:38:39 +0100 Subject: [PATCH] Support CORS --- main.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index d2d9f85..41b175c 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( oclib "cloud.o-forge.io/core/oc-lib" "cloud.o-forge.io/core/oc-lib/tools" beego "github.com/beego/beego/v2/server/web" + "github.com/beego/beego/v2/server/web/filter/cors" ) const appname = "oc-datacenter" @@ -33,6 +34,12 @@ func main() { beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger" api := &tools.API{} api.Discovered(beego.BeeApp.Handlers.GetAllControllerInfo()) - + beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{ + AllowAllOrigins: true, + AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}, + AllowHeaders: []string{"Origin", "Authorization", "Content-Type"}, + ExposeHeaders: []string{"Content-Length", "Content-Type"}, + AllowCredentials: true, + })) beego.Run() }