Class: FluidCLI::Theme::DevServer

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/fluid_cli/theme/dev_server.rb,
lib/fluid_cli/theme/dev_server/sse.rb,
lib/fluid_cli/theme/dev_server/proxy.rb,
lib/fluid_cli/theme/dev_server/errors.rb,
lib/fluid_cli/theme/dev_server/watcher.rb,
lib/fluid_cli/theme/dev_server/hot_reload.rb,
lib/fluid_cli/theme/dev_server/web_server.rb,
lib/fluid_cli/theme/dev_server/header_hash.rb,
lib/fluid_cli/theme/dev_server/reload_mode.rb,
lib/fluid_cli/theme/dev_server/local_assets.rb,
lib/fluid_cli/theme/dev_server/certificate_manager.rb,
lib/fluid_cli/theme/dev_server/proxy_param_builder.rb,
lib/fluid_cli/theme/dev_server/hooks/file_change_hook.rb,
lib/fluid_cli/theme/dev_server/hot_reload/script_injector.rb

Defined Under Namespace

Modules: Hooks, WEBrickGenericServerThreadJoinWithTimeout Classes: CertificateManager, Error, HeaderHash, HotReload, LocalAssets, Proxy, ProxyParamBuilder, ReloadMode, 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.



31
32
33
# File 'lib/fluid_cli/theme/dev_server.rb', line 31

def app
  @app
end

#blockObject (readonly)

Returns the value of attribute block.



31
32
33
# File 'lib/fluid_cli/theme/dev_server.rb', line 31

def block
  @block
end

#ctxObject (readonly)

Returns the value of attribute ctx.



31
32
33
# File 'lib/fluid_cli/theme/dev_server.rb', line 31

def ctx
  @ctx
end

#editor_syncObject (readonly)

Returns the value of attribute editor_sync.



31
32
33
# File 'lib/fluid_cli/theme/dev_server.rb', line 31

def editor_sync
  @editor_sync
end

#forceObject (readonly)

Returns the value of attribute force.



31
32
33
# File 'lib/fluid_cli/theme/dev_server.rb', line 31

def force
  @force
end

#hostObject (readonly)

Returns the value of attribute host.



31
32
33
# File 'lib/fluid_cli/theme/dev_server.rb', line 31

def host
  @host
end

#ignoresObject (readonly)

Returns the value of attribute ignores.



31
32
33
# File 'lib/fluid_cli/theme/dev_server.rb', line 31

def ignores
  @ignores
end

#includesObject (readonly)

Returns the value of attribute includes.



31
32
33
# File 'lib/fluid_cli/theme/dev_server.rb', line 31

def includes
  @includes
end

#modeObject (readonly)

Returns the value of attribute mode.



31
32
33
# File 'lib/fluid_cli/theme/dev_server.rb', line 31

def mode
  @mode
end

Returns the value of attribute navigate.



31
32
33
# File 'lib/fluid_cli/theme/dev_server.rb', line 31

def navigate
  @navigate
end

#pollObject (readonly)

Returns the value of attribute poll.



31
32
33
# File 'lib/fluid_cli/theme/dev_server.rb', line 31

def poll
  @poll
end

#portObject (readonly)

Returns the value of attribute port.



31
32
33
# File 'lib/fluid_cli/theme/dev_server.rb', line 31

def port
  @port
end

#rootObject (readonly)

Returns the value of attribute root.



31
32
33
# File 'lib/fluid_cli/theme/dev_server.rb', line 31

def root
  @root
end

#stoppedObject (readonly)

Returns the value of attribute stopped.



31
32
33
# File 'lib/fluid_cli/theme/dev_server.rb', line 31

def stopped
  @stopped
end

#theme_identifierObject (readonly)

Returns the value of attribute theme_identifier.



31
32
33
# File 'lib/fluid_cli/theme/dev_server.rb', line 31

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, force: false, overwrite_json: false, navigate: false, mode: ReloadMode.default, includes: nil, ignores: nil, &block) ⇒ Object



35
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
68
# File 'lib/fluid_cli/theme/dev_server.rb', line 35

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

.stopObject



70
71
72
# File 'lib/fluid_cli/theme/dev_server.rb', line 70

def stop
  instance.stop
end

Instance Method Details

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

rubocop:disable Metrics/ParameterLists



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
104
105
106
# File 'lib/fluid_cli/theme/dev_server.rb', line 76

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

#startObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/fluid_cli/theme/dev_server.rb', line 108

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 FluidCLI::API::APIRequestForbiddenError,
       FluidCLI::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



132
133
134
135
136
137
138
139
140
# File 'lib/fluid_cli/theme/dev_server.rb', line 132

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

  @stopped = true

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