Skip to content

Commit

Permalink
feat: add configuration for graphql server port
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmc committed Jun 28, 2022
1 parent ad6ad3d commit ccd4b9e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
5 changes: 3 additions & 2 deletions gql/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
const DummyDealsDir = "/tmp/dummy"
const DummyDealsPrefix = "dummy"

var DummyDealsBase = fmt.Sprintf("http://localhost:%d/"+DummyDealsPrefix, httpPort)
var DummyDealsBase string

func serveDummyDeals(mux *http.ServeMux) error {
func serveDummyDeals(mux *http.ServeMux, port int) error {
DummyDealsBase = fmt.Sprintf("http://localhost:%d/"+DummyDealsPrefix, port)
dpath := "/" + DummyDealsPrefix + "/"
if err := os.MkdirAll(DummyDealsDir, 0755); err != nil {
return fmt.Errorf("failed to mk directory %s for dummy deals: %w", DummyDealsDir, err)
Expand Down
5 changes: 3 additions & 2 deletions gql/dummy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ func TestDummyServer(t *testing.T) {
ctx := context.Background()

mux := http.NewServeMux()
listenAddr := fmt.Sprintf(":%d", httpPort)
port := 8080
listenAddr := fmt.Sprintf(":%d", port)
t.Logf("server listening on %s\n", listenAddr)
err := serveDummyDeals(mux)
err := serveDummyDeals(mux, port)
rq.NoError(err)

srv := &http.Server{Addr: listenAddr, Handler: mux}
Expand Down
9 changes: 4 additions & 5 deletions gql/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (

var log = logging.Logger("gql")

const httpPort = 8080

type Server struct {
resolver *resolver
srv *http.Server
Expand All @@ -47,13 +45,14 @@ func (s *Server) Start(ctx context.Context) error {
}

// Serve dummy deals
err = serveDummyDeals(mux)
port := int(s.resolver.cfg.Graphql.Port)
err = serveDummyDeals(mux, port)
if err != nil {
return err
}

// GraphQL handler (GUI for making GraphQL queries)
mux.HandleFunc("/graphiql", graphiql(httpPort))
mux.HandleFunc("/graphiql", graphiql(port))

// Allow resolving directly to fields (instead of requiring resolvers to
// have a method for every GraphQL field)
Expand All @@ -73,7 +72,7 @@ func (s *Server) Start(ctx context.Context) error {
}
wsHandler := graphqlws.NewHandlerFunc(schema, queryHandler, wsOpts...)

listenAddr := fmt.Sprintf(":%d", httpPort)
listenAddr := fmt.Sprintf(":%d", port)
s.srv = &http.Server{Addr: listenAddr, Handler: mux}
fmt.Printf("Graphql server listening on %s\n", listenAddr)
mux.Handle("/graphql/subscription", &corsHandler{wsHandler})
Expand Down
4 changes: 4 additions & 0 deletions node/config/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func DefaultBoost() *Boost {
ParallelFetchLimit: 10,
},

Graphql: GraphqlConfig{
Port: 8080,
},

Dealmaking: DealmakingConfig{
ConsiderOnlineStorageDeals: true,
ConsiderOfflineStorageDeals: true,
Expand Down
6 changes: 6 additions & 0 deletions node/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Boost struct {
SectorIndexApiInfo string
Dealmaking DealmakingConfig
Wallets WalletsConfig
Graphql GraphqlConfig

// Lotus configs
LotusDealmaking lotus_config.DealmakingConfig
Expand Down Expand Up @@ -69,6 +70,11 @@ type WalletsConfig struct {
PledgeCollateral string
}

type GraphqlConfig struct {
// The port that the graphql server listens on
Port uint64
}

type LotusDealmakingConfig struct {
// A list of Data CIDs to reject when making deals
PieceCidBlocklist []cid.Cid
Expand Down

0 comments on commit ccd4b9e

Please sign in to comment.