Skip to content

Commit

Permalink
Allow CORS on RPC
Browse files Browse the repository at this point in the history
Fixes #1329
  • Loading branch information
omerfirmak authored and wojciechos committed Oct 11, 2023
1 parent ed8ef1c commit 06489cb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ require (
github.com/quic-go/webtransport-go v0.5.3 // indirect
github.com/raulk/go-watchdog v1.3.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/rs/cors v1.10.1 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/sourcegraph/sourcegraph/lib v0.0.0-20221216004406-749998a2ac74 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,8 @@ github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDN
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/rs/cors v1.10.1 h1:L0uuZVXIKlI1SShY2nhFfo44TYvDPQ1w4oFkUJNfhyo=
github.com/rs/cors v1.10.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand Down
5 changes: 3 additions & 2 deletions node/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/NethermindEth/juno/utils"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/rs/cors"
"github.com/sourcegraph/conc"
"google.golang.org/grpc"
)
Expand Down Expand Up @@ -66,15 +67,15 @@ func makeRPCOverHTTP(host string, port uint16, jsonrpcServer *jsonrpc.Server, lo
mux := http.NewServeMux()
mux.Handle("/", httpHandler)
mux.Handle("/v0_4", httpHandler)
return makeHTTPService(host, port, mux)
return makeHTTPService(host, port, cors.Default().Handler(mux))
}

func makeRPCOverWebsocket(host string, port uint16, jsonrpcServer *jsonrpc.Server, log utils.SimpleLogger) *httpService {
wsHandler := jsonrpc.NewWebsocket(jsonrpcServer, log)
mux := http.NewServeMux()
mux.Handle("/", wsHandler)
mux.Handle("/v0_4", wsHandler)
return makeHTTPService(host, port, mux)
return makeHTTPService(host, port, cors.Default().Handler(mux))
}

func makeMetrics(host string, port uint16) *httpService {
Expand Down

0 comments on commit 06489cb

Please sign in to comment.