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

Fix theme serve failing with the --host property #1766

Merged
merged 2 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ From version 2.6.0, the sections in this file adhere to the [keep a changelog](h
## [Unreleased]
### Fixed
* [#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
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