Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Fix theme serve failing with the --host property (#1766)
Browse files Browse the repository at this point in the history
  • Loading branch information
karreiro authored and Pedro Piñera committed Nov 23, 2021
1 parent 2d53e5b commit 693b3d8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ 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
* [#1722](https://github.com/Shopify/shopify-cli/pull/1722): Fix `theme serve` failing when the port is already being used
Expand Down
2 changes: 1 addition & 1 deletion lib/project_types/theme/commands/serve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/shopify_cli/theme/dev_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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!

Expand Down Expand Up @@ -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: [],
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions test/project_types/theme/commands/serve_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 693b3d8

Please sign in to comment.