Class: ShopifyCLI::Theme::DevServer

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/shopify_cli/theme/dev_server.rb,
lib/shopify_cli/theme/dev_server/sse.rb,
lib/shopify_cli/theme/dev_server/proxy.rb,
lib/shopify_cli/theme/dev_server/errors.rb,
lib/shopify_cli/theme/dev_server/watcher.rb,
lib/shopify_cli/theme/dev_server/cdn_fonts.rb,
lib/shopify_cli/theme/dev_server/hot_reload.rb,
lib/shopify_cli/theme/dev_server/web_server.rb,
lib/shopify_cli/theme/dev_server/header_hash.rb,
lib/shopify_cli/theme/dev_server/reload_mode.rb,
lib/shopify_cli/theme/dev_server/local_assets.rb,
lib/shopify_cli/theme/dev_server/remote_watcher.rb,
lib/shopify_cli/theme/dev_server/certificate_manager.rb,
lib/shopify_cli/theme/dev_server/proxy_param_builder.rb,
lib/shopify_cli/theme/dev_server/hooks/file_change_hook.rb,
lib/shopify_cli/theme/dev_server/hot_reload/sections_index.rb,
lib/shopify_cli/theme/dev_server/hot_reload/script_injector.rb,
lib/shopify_cli/theme/dev_server/hot_reload/remote_file_deleter.rb,
lib/shopify_cli/theme/dev_server/hot_reload/remote_file_reloader.rb,
lib/shopify_cli/theme/dev_server/remote_watcher/json_files_update_job.rb

Direct Known Subclasses

Extension::DevServer

Defined Under Namespace

Modules: Hooks, WEBrickGenericServerThreadJoinWithTimeout Classes: CdnFonts, CertificateManager, Error, HeaderHash, HotReload, LocalAssets, Proxy, ProxyParamBuilder, ReloadMode, RemoteWatcher, SSE, Watcher, WebServer

Constant Summary collapse

HOP_BY_HOP_HEADERS =
[
  "connection",
  "keep-alive",
  "proxy-authenticate",
  "proxy-authorization",
  "te",
  "trailer",
  "transfer-encoding",
  "upgrade",
  "content-security-policy",
  "content-length",
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



32
33
34
# File 'lib/shopify_cli/theme/dev_server.rb', line 32

def app
  @app
end

#blockObject (readonly)

Returns the value of attribute block.



32
33
34
# File 'lib/shopify_cli/theme/dev_server.rb', line 32

def block
  @block
end

#ctxObject (readonly)

Returns the value of attribute ctx.



32
33
34
# File 'lib/shopify_cli/theme/dev_server.rb', line 32

def ctx
  @ctx
end

#editor_syncObject (readonly)

Returns the value of attribute editor_sync.



32
33
34
# File 'lib/shopify_cli/theme/dev_server.rb', line 32

def editor_sync
  @editor_sync
end

#hostObject (readonly)

Returns the value of attribute host.



32
33
34
# File 'lib/shopify_cli/theme/dev_server.rb', line 32

def host
  @host
end

#ignoresObject (readonly)

Returns the value of attribute ignores.



32
33
34
# File 'lib/shopify_cli/theme/dev_server.rb', line 32

def ignores
  @ignores
end

#includesObject (readonly)

Returns the value of attribute includes.



32
33
34
# File 'lib/shopify_cli/theme/dev_server.rb', line 32

def includes
  @includes
end

#modeObject (readonly)

Returns the value of attribute mode.



32
33
34
# File 'lib/shopify_cli/theme/dev_server.rb', line 32

def mode
  @mode
end

#pollObject (readonly)

Returns the value of attribute poll.



32
33
34
# File 'lib/shopify_cli/theme/dev_server.rb', line 32

def poll
  @poll
end

#portObject (readonly)

Returns the value of attribute port.



32
33
34
# File 'lib/shopify_cli/theme/dev_server.rb', line 32

def port
  @port
end

#rootObject (readonly)

Returns the value of attribute root.



32
33
34
# File 'lib/shopify_cli/theme/dev_server.rb', line 32

def root
  @root
end

#stableObject (readonly)

Returns the value of attribute stable.



32
33
34
# File 'lib/shopify_cli/theme/dev_server.rb', line 32

def stable
  @stable
end

#stoppedObject (readonly)

Returns the value of attribute stopped.



32
33
34
# File 'lib/shopify_cli/theme/dev_server.rb', line 32

def stopped
  @stopped
end

#theme_identifierObject (readonly)

Returns the value of attribute theme_identifier.



32
33
34
# File 'lib/shopify_cli/theme/dev_server.rb', line 32

def theme_identifier
  @theme_identifier
end

Class Method Details

.start(ctx, root, host: "127.0.0.1", theme: nil, port: 9292, poll: false, editor_sync: false, overwrite_json: false, stable: false, mode: ReloadMode.default, includes: nil, ignores: nil, &block) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/shopify_cli/theme/dev_server.rb', line 36

def start(
  ctx,
  root,
  host: "127.0.0.1",
  theme: nil,
  port: 9292,
  poll: false,
  editor_sync: false,
  overwrite_json: false,
  stable: false,
  mode: ReloadMode.default,
  includes: nil,
  ignores: nil,
  &block
)
  instance.setup(
    ctx,
    root,
    host,
    theme,
    port,
    poll,
    editor_sync,
    overwrite_json,
    stable,
    mode,
    includes,
    ignores,
    &block
  )
  instance.start
end

.stopObject



69
70
71
# File 'lib/shopify_cli/theme/dev_server.rb', line 69

def stop
  instance.stop
end

Instance Method Details

#setup(ctx, root, host, theme_identifier, port, poll, editor_sync, overwrite_json, stable, mode, includes, ignores, &block) ⇒ Object

rubocop:disable Metrics/ParameterLists



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/shopify_cli/theme/dev_server.rb', line 75

def setup(
  ctx,
  root,
  host,
  theme_identifier,
  port,
  poll,
  editor_sync,
  overwrite_json,
  stable,
  mode,
  includes,
  ignores,
  &block
)
  @ctx = ctx
  @root = root
  @host = host
  @theme_identifier = theme_identifier
  @port = port
  @poll = poll
  @editor_sync = editor_sync
  @overwrite_json = overwrite_json
  @stable = stable
  @mode = mode
  @includes = includes
  @ignores = ignores
  @block = block
end

#startObject



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/shopify_cli/theme/dev_server.rb', line 105

def start
  sync_theme

  # Handle process stop
  trap("INT") { stop("SIGINT") }
  trap("TERM") { stop("SIGTERM") }

  # Setup the middleware stack. Mimics Rack::Builder / config.ru, but in reverse order
  @app = middleware_stack

  # Start development server
  setup_server
  start_server
  teardown_server

rescue ShopifyCLI::API::APIRequestForbiddenError,
       ShopifyCLI::API::APIRequestUnauthorizedError
  ctx.abort(ensure_user_message)
rescue Errno::EADDRINUSE
  ctx.abort(port_error_message, port_error_help_message)
rescue Errno::EADDRNOTAVAIL
  ctx.abort(binding_error_message)
end

#stop(signal = nil) ⇒ Object



129
130
131
132
133
134
135
136
137
# File 'lib/shopify_cli/theme/dev_server.rb', line 129

def stop(signal = nil)
  ctx.debug(stop_signal(signal)) unless signal.nil?

  @stopped = true

  ctx.puts(stopping_message)
  app.close
  WebServer.shutdown
end