diff --git a/cmd/booster-http/http_test.go b/cmd/booster-http/http_test.go index 4a96ba4db..377c079b7 100644 --- a/cmd/booster-http/http_test.go +++ b/cmd/booster-http/http_test.go @@ -23,7 +23,7 @@ const testFile = "test/test_file" func TestNewHttpServer(t *testing.T) { // Create a new mock Http server ctrl := gomock.NewController(t) - httpServer := NewHttpServer("", 7777, mocks_booster_http.NewMockHttpServerApi(ctrl), nil) + httpServer := NewHttpServer("", "0.0.0.0", 7777, mocks_booster_http.NewMockHttpServerApi(ctrl), nil) err := httpServer.Start(context.Background()) require.NoError(t, err) waitServerUp(t, 7777) @@ -42,7 +42,7 @@ func TestHttpGzipResponse(t *testing.T) { // Create a new mock Http server with custom functions ctrl := gomock.NewController(t) mockHttpServer := mocks_booster_http.NewMockHttpServerApi(ctrl) - httpServer := NewHttpServer("", 7777, mockHttpServer, nil) + httpServer := NewHttpServer("", "0.0.0.0", 7777, mockHttpServer, nil) err := httpServer.Start(context.Background()) require.NoError(t, err) waitServerUp(t, 7777) @@ -109,7 +109,7 @@ func TestHttpInfo(t *testing.T) { // Create a new mock Http server ctrl := gomock.NewController(t) - httpServer := NewHttpServer("", 7777, mocks_booster_http.NewMockHttpServerApi(ctrl), nil) + httpServer := NewHttpServer("", "0.0.0.0", 7777, mocks_booster_http.NewMockHttpServerApi(ctrl), nil) err := httpServer.Start(context.Background()) require.NoError(t, err) waitServerUp(t, 7777) diff --git a/cmd/booster-http/mocks/mock_booster_http.go b/cmd/booster-http/mocks/mock_booster_http.go index 1af9d3451..4f1eca760 100644 --- a/cmd/booster-http/mocks/mock_booster_http.go +++ b/cmd/booster-http/mocks/mock_booster_http.go @@ -8,8 +8,8 @@ import ( context "context" reflect "reflect" - mount "github.com/filecoin-project/dagstore/mount" piecestore "github.com/filecoin-project/boost-gfm/piecestore" + mount "github.com/filecoin-project/dagstore/mount" abi "github.com/filecoin-project/go-state-types/abi" gomock "github.com/golang/mock/gomock" cid "github.com/ipfs/go-cid" diff --git a/cmd/booster-http/run.go b/cmd/booster-http/run.go index e9832aaf0..021037cb8 100644 --- a/cmd/booster-http/run.go +++ b/cmd/booster-http/run.go @@ -42,6 +42,12 @@ var runCmd = &cli.Command{ Usage: "the base path at which to run the web server", Value: "", }, + &cli.StringFlag{ + Name: "address", + Aliases: []string{"addr"}, + Usage: "the listen address for the web server", + Value: "0.0.0.0", + }, &cli.UintFlag{ Name: "port", Usage: "the port the web server listens on", @@ -201,14 +207,15 @@ var runCmd = &cli.Command{ sapi := serverApi{ctx: ctx, bapi: bapi, sa: sa} server := NewHttpServer( cctx.String("base-path"), + cctx.String("address"), cctx.Int("port"), sapi, opts, ) // Start the server - log.Infof("Starting booster-http node on port %d with base path '%s'", - cctx.Int("port"), cctx.String("base-path")) + log.Infof("Starting booster-http node on listen address %s and port %d with base path '%s'", + cctx.String("address"), cctx.Int("port"), cctx.String("base-path")) err = server.Start(ctx) if err != nil { return fmt.Errorf("starting http server: %w", err) diff --git a/cmd/booster-http/server.go b/cmd/booster-http/server.go index 8cf321d44..a4d40f355 100644 --- a/cmd/booster-http/server.go +++ b/cmd/booster-http/server.go @@ -42,11 +42,12 @@ type apiVersion struct { } type HttpServer struct { - path string - port int - api HttpServerApi - opts HttpServerOptions - idxPage string + path string + listenAddr string + port int + api HttpServerApi + opts HttpServerOptions + idxPage string ctx context.Context cancel context.CancelFunc @@ -65,11 +66,11 @@ type HttpServerOptions struct { SupportedResponseFormats []string } -func NewHttpServer(path string, port int, api HttpServerApi, opts *HttpServerOptions) *HttpServer { +func NewHttpServer(path string, listenAddr string, port int, api HttpServerApi, opts *HttpServerOptions) *HttpServer { if opts == nil { opts = &HttpServerOptions{ServePieces: true} } - return &HttpServer{path: path, port: port, api: api, opts: *opts, idxPage: parseTemplate(*opts)} + return &HttpServer{path: path, listenAddr: listenAddr, port: port, api: api, opts: *opts, idxPage: parseTemplate(*opts)} } func (s *HttpServer) pieceBasePath() string { @@ -102,7 +103,7 @@ func (s *HttpServer) Start(ctx context.Context) error { handler.HandleFunc("/info", s.handleInfo) handler.Handle("/metrics", metrics.Exporter("booster_http")) // metrics s.server = &http.Server{ - Addr: fmt.Sprintf(":%d", s.port), + Addr: fmt.Sprintf("%s:%d", s.listenAddr, s.port), Handler: handler, // This context will be the parent of the context associated with all // incoming requests