From b1741b68c0d0e0a182bf03a22bab6c781144f8f6 Mon Sep 17 00:00:00 2001 From: Ahmed Mohamed Ibrahim Date: Thu, 13 Apr 2023 17:46:48 +0200 Subject: [PATCH] set cors middleware in response headers --- middleware.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/middleware.go b/middleware.go index f837f2a..081f5ff 100644 --- a/middleware.go +++ b/middleware.go @@ -24,9 +24,9 @@ func (r *Router) Use(method string, middlewares ...interface{}) { func CORSMiddleware() MiddlewareFunc { return func(handler Handler) Handler { return func(ctx *Context) error { - ctx.SetRequestHeader("Access-Control-Allow-Origin", "*") - ctx.SetRequestHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE") - ctx.SetRequestHeader("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization") + ctx.SetResponseHeader("Access-Control-Allow-Origin", "*") + ctx.SetResponseHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE") + ctx.SetResponseHeader("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization") return handler(ctx) } }