From c657a3a7dacf3450004ff586f048ea2aabfdf333 Mon Sep 17 00:00:00 2001 From: nquidox Date: Tue, 9 Sep 2025 23:18:17 +0300 Subject: [PATCH] cors block added --- internal/router/handler.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/internal/router/handler.go b/internal/router/handler.go index 0c2aa4b..875ed3f 100644 --- a/internal/router/handler.go +++ b/internal/router/handler.go @@ -1,6 +1,7 @@ package router import ( + "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" swaggerFiles "github.com/swaggo/files" @@ -8,6 +9,7 @@ import ( "merch-parser-api/internal/interfaces" "merch-parser-api/internal/shared" "net/http" + "time" ) type router struct { @@ -38,6 +40,15 @@ func NewRouter(deps Deps) interfaces.Router { } } + engine.Use(cors.New(cors.Config{ + AllowOrigins: []string{"http://localhost:5173"}, + AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}, + AllowHeaders: []string{"Origin", "Content-Type", "Authorization"}, + ExposeHeaders: []string{"Content-Length"}, + AllowCredentials: true, + MaxAge: 12 * time.Hour, + })) + return &router{ apiPrefix: deps.ApiPrefix, engine: engine,