From 84077be723cb9428b054335d21d594c975a5ccfa Mon Sep 17 00:00:00 2001 From: Harsh Khandeparkar Date: Tue, 14 Nov 2023 03:42:55 +0530 Subject: [PATCH] feat: enabled cors --- cmd/backend.go | 3 ++- go.mod | 2 ++ go.sum | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/backend.go b/cmd/backend.go index 366a21ee..c3e5f7f6 100644 --- a/cmd/backend.go +++ b/cmd/backend.go @@ -11,6 +11,7 @@ import ( "github.com/kossiitkgp/kwoc-backend/v2/server" "github.com/kossiitkgp/kwoc-backend/v2/utils" + "github.com/gorilla/handlers" "github.com/joho/godotenv" "github.com/rs/zerolog" "github.com/rs/zerolog/log" @@ -84,7 +85,7 @@ func main() { }() log.Info().Msg("Starting server on port : " + port) - err = http.ListenAndServe(":"+port, router) + err = http.ListenAndServe(":"+port, handlers.CORS()(router)) if err != nil { log.Fatal().Err(err).Msg("Error starting the server.") diff --git a/go.mod b/go.mod index 08350f01..e9dd1162 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.19 require ( github.com/golang-jwt/jwt/v5 v5.0.0 + github.com/gorilla/handlers v1.5.2 github.com/gorilla/mux v1.8.0 github.com/joho/godotenv v1.5.1 github.com/rs/zerolog v1.28.0 @@ -13,6 +14,7 @@ require ( ) require ( + github.com/felixge/httpsnoop v1.0.3 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect github.com/jackc/pgx/v5 v5.3.1 // indirect diff --git a/go.sum b/go.sum index 42b3ea95..c2b39cf2 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,13 @@ github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk= +github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/gorilla/handlers v1.5.2 h1:cLTUSsNkgcwhgRqvCNmdbRWG0A3N4F+M2nWKdScwyEE= +github.com/gorilla/handlers v1.5.2/go.mod h1:dX+xVpaxdSw+q0Qek8SSsl3dfMk3jNddUkMzo0GtH0w= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=