diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c22517b03..3ef01629e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ From version 2.6.0, the sections in this file adhere to the [keep a changelog](h ### Fixed * [#1763](https://github.com/Shopify/shopify-cli/pull/1763): Fix: Tunnel --PORT parameter not working in Node.js app. * [#1769](https://github.com/Shopify/shopify-cli/pull/1769): Fix `theme push --development --json` to output the proper exit code +* [#1766](https://github.com/Shopify/shopify-cli/pull/1766): Fix `theme serve` failing with the `--host` property ## Version 2.7.1 ### Fixed diff --git a/lib/project_types/theme/commands/serve.rb b/lib/project_types/theme/commands/serve.rb index eeaeb073bd..8b1a0b2142 100644 --- a/lib/project_types/theme/commands/serve.rb +++ b/lib/project_types/theme/commands/serve.rb @@ -15,7 +15,7 @@ class Serve < ShopifyCLI::Command::SubCommand def call(*) flags = options.flags.dup host = flags[:host] || DEFAULT_HTTP_HOST - ShopifyCLI::Theme::DevServer.start(@ctx, ".", http_bind: host, **flags) do |syncer| + ShopifyCLI::Theme::DevServer.start(@ctx, ".", host: host, **flags) do |syncer| UI::SyncProgressBar.new(syncer).progress(:upload_theme!, delay_low_priority_files: true) end rescue ShopifyCLI::Theme::DevServer::AddressBindingError diff --git a/lib/shopify_cli/theme/dev_server.rb b/lib/shopify_cli/theme/dev_server.rb index 28ce755cfc..1dbbe86205 100644 --- a/lib/shopify_cli/theme/dev_server.rb +++ b/lib/shopify_cli/theme/dev_server.rb @@ -24,7 +24,7 @@ module DevServer class << self attr_accessor :ctx - def start(ctx, root, http_bind: "127.0.0.1", port: 9292, poll: false) + def start(ctx, root, host: "127.0.0.1", port: 9292, poll: false) @ctx = ctx theme = DevelopmentTheme.new(ctx, root: root) ignore_filter = IgnoreFilter.from_path(root) @@ -36,7 +36,7 @@ def start(ctx, root, http_bind: "127.0.0.1", port: 9292, poll: false) @app = LocalAssets.new(ctx, @app, theme: theme) @app = HotReload.new(ctx, @app, theme: theme, watcher: watcher, ignore_filter: ignore_filter) stopped = false - address = "http://#{http_bind}:#{port}" + address = "http://#{host}:#{port}" theme.ensure_exists! @@ -70,7 +70,7 @@ def start(ctx, root, http_bind: "127.0.0.1", port: 9292, poll: false) watcher.start WebServer.run( @app, - BindAddress: http_bind, + BindAddress: host, Port: port, Logger: logger, AccessLog: [], @@ -83,7 +83,7 @@ def start(ctx, root, http_bind: "127.0.0.1", port: 9292, poll: false) rescue Errno::EADDRINUSE abort_address_already_in_use(address) rescue Errno::EADDRNOTAVAIL - raise AddressBindingError, "Error binding to the address #{http_bind}." + raise AddressBindingError, "Error binding to the address #{host}." end def stop diff --git a/test/project_types/theme/commands/serve_test.rb b/test/project_types/theme/commands/serve_test.rb index 76bf64070c..8ec91701c7 100644 --- a/test/project_types/theme/commands/serve_test.rb +++ b/test/project_types/theme/commands/serve_test.rb @@ -11,7 +11,7 @@ def test_serve_command context = ShopifyCLI::Context.new ShopifyCLI::Theme::DevServer .expects(:start) - .with(context, ".", http_bind: Theme::Command::Serve::DEFAULT_HTTP_HOST) + .with(context, ".", host: Theme::Command::Serve::DEFAULT_HTTP_HOST) Theme::Command::Serve.new(context).call end @@ -20,7 +20,7 @@ def test_serve_command_raises_abort_when_cant_bind_address context = ShopifyCLI::Context.new ShopifyCLI::Theme::DevServer .expects(:start) - .with(context, ".", http_bind: Theme::Command::Serve::DEFAULT_HTTP_HOST) + .with(context, ".", host: Theme::Command::Serve::DEFAULT_HTTP_HOST) .raises(ShopifyCLI::Theme::DevServer::AddressBindingError) assert_raises ShopifyCLI::Abort do @@ -30,17 +30,17 @@ def test_serve_command_raises_abort_when_cant_bind_address def test_can_specify_bind_address context = ShopifyCLI::Context.new - ShopifyCLI::Theme::DevServer.expects(:start).with(context, ".", http_bind: "0.0.0.0") + ShopifyCLI::Theme::DevServer.expects(:start).with(context, ".", host: "0.0.0.0") command = Theme::Command::Serve.new(context) - command.options.flags[:http_bind] = "0.0.0.0" + command.options.flags[:host] = "0.0.0.0" command.call end def test_can_specify_port context = ShopifyCLI::Context.new ShopifyCLI::Theme::DevServer.expects(:start).with(context, ".", - http_bind: Theme::Command::Serve::DEFAULT_HTTP_HOST, port: 9293) + host: Theme::Command::Serve::DEFAULT_HTTP_HOST, port: 9293) command = Theme::Command::Serve.new(context) command.options.flags[:port] = 9293 @@ -50,7 +50,7 @@ def test_can_specify_port def test_can_specify_poll context = ShopifyCLI::Context.new ShopifyCLI::Theme::DevServer.expects(:start).with(context, ".", - http_bind: Theme::Command::Serve::DEFAULT_HTTP_HOST, poll: true) + host: Theme::Command::Serve::DEFAULT_HTTP_HOST, poll: true) command = Theme::Command::Serve.new(context) command.options.flags[:poll] = true