From 1d616b8c6f9c27679f739840539f5f5137f14df0 Mon Sep 17 00:00:00 2001 From: Nathan Seva Date: Fri, 4 Nov 2022 17:04:42 +0100 Subject: [PATCH] Allow cors (#244) adds cors middleware --- .gitignore | 5 ++++- api/swagger/server/restapi/configure_thyra_server.go | 5 ++++- go.mod | 1 + go.sum | 2 ++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index da4aeeefb..b720b893c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ .vscode wallet_*.json -*.exe \ No newline at end of file +*.exe + +# air temporary directory +tmp/ \ No newline at end of file diff --git a/api/swagger/server/restapi/configure_thyra_server.go b/api/swagger/server/restapi/configure_thyra_server.go index 21a34a944..6159f7f80 100644 --- a/api/swagger/server/restapi/configure_thyra_server.go +++ b/api/swagger/server/restapi/configure_thyra_server.go @@ -11,6 +11,7 @@ import ( "github.com/go-openapi/errors" "github.com/go-openapi/runtime" "github.com/go-openapi/runtime/middleware" + "github.com/rs/cors" "github.com/massalabs/thyra/api/swagger/server/restapi/operations" "github.com/massalabs/thyra/pkg/onchain/website" @@ -107,5 +108,7 @@ func setupMiddlewares(handler http.Handler) http.Handler { // The middleware configuration happens before anything, this middleware also applies to serving the swagger.json document. // So this is a good place to plug in a panic handling middleware, logging and metrics. func setupGlobalMiddleware(handler http.Handler) http.Handler { - return website.TopMiddleware(handler) + handleCORS := cors.Default().Handler + + return website.TopMiddleware(handleCORS(handler)) } diff --git a/go.mod b/go.mod index cab0d381b..56d2f4cd7 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/go-openapi/swag v0.21.1 github.com/go-openapi/validate v0.21.0 github.com/jessevdk/go-flags v1.5.0 + github.com/rs/cors v1.8.2 golang.org/x/net v0.0.0-20220722155237-a158d28d115b ) diff --git a/go.sum b/go.sum index b753691a1..c1ed355ab 100644 --- a/go.sum +++ b/go.sum @@ -368,6 +368,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg= github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= +github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U= +github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=