Class: Lifer::Dev::Server
- Inherits:
-
Object
- Object
- Lifer::Dev::Server
- Defined in:
- lib/lifer/dev/server.rb
Overview
This server is used in development and test modes to preview and serve a Lifer project. It’s for convenience and is not super sophisticated. The server wraps a Puma process with some reasonable, default settings. It also listens for file changes and rebuilds the project on the next request made to the web server.
Constant Summary collapse
- DEFAULT_PORT =
The default port to run the Puma server on.
9292
Class Method Summary collapse
-
.rack_app ⇒ Array
A proc that follows the [Rack server specification].
-
.start!(port:) ⇒ void
Start a Puma server to preview your Lifer project locally.
Class Method Details
.rack_app ⇒ Array
A proc that follows the [Rack server specification]. Because we don’t want to commit a rackup configuration file at this time, any “middleware” we want to insert should be a part of this method.
51 52 53 54 55 56 |
# File 'lib/lifer/dev/server.rb', line 51 def rack_app -> (env) { reload! router.response_for(env) } end |
.start!(port:) ⇒ void
This method returns an undefined value.
Start a Puma server to preview your Lifer project locally.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/lifer/dev/server.rb', line 29 def start!(port:) puma_configuration = Puma::Configuration.new do |config| config.app rack_app config.bind "tcp://127.0.0.1:#{port || DEFAULT_PORT}" config.environment "development" config.log_requests true end Lifer.build!(environment: :serve) listener.start Puma::Launcher.new(puma_configuration).run end |