Class: Middleman::PreviewServer
- Inherits:
-
Object
- Object
- Middleman::PreviewServer
- Extended by:
- Forwardable
- Defined in:
- lib/middleman-core/preview_server.rb,
lib/middleman-core/preview_server/checks.rb,
lib/middleman-core/preview_server/server_url.rb,
lib/middleman-core/preview_server/information.rb,
lib/middleman-core/preview_server/server_hostname.rb,
lib/middleman-core/preview_server/tcp_port_prober.rb,
lib/middleman-core/preview_server/server_ip_address.rb,
lib/middleman-core/preview_server/server_information.rb,
lib/middleman-core/preview_server/network_interface_inventory.rb,
lib/middleman-core/preview_server/server_information_validator.rb,
lib/middleman-core/preview_server/server_information_callback_proxy.rb
Defined Under Namespace
Modules: Checks Classes: AllInterfaces, AllIpv4Interfaces, AllIpv6Interfaces, BasicInformation, BasicServerIpAddress, BindAddressAndServerNameInformation, BindAddressInformation, DefaultInformation, FilteredWebrickLog, NetworkInterfaceInventory, ServerHostname, ServerInformation, ServerInformationCallbackProxy, ServerInformationValidator, ServerIpAddress, ServerIpv4Address, ServerIpv6Address, ServerNameInformation, ServerNameIsIpInformation, ServerUrl, TcpPortProber
Class Attribute Summary collapse
-
.app ⇒ Object
readonly
Returns the value of attribute app.
-
.environment ⇒ Object
readonly
Returns the value of attribute environment.
-
.server_information ⇒ Object
readonly
Returns the value of attribute server_information.
-
.ssl_certificate ⇒ Object
readonly
Returns the value of attribute ssl_certificate.
-
.ssl_private_key ⇒ Object
readonly
Returns the value of attribute ssl_private_key.
Class Method Summary collapse
-
.reload
Simply stop, then start the server.
-
.shutdown
Stop the current instance, exit Webrick.
-
.start(opts = {}, cli_options = {})
Start an instance of Middleman::Application.
-
.stop
Detach the current Middleman::Application instance.
Class Attribute Details
.app ⇒ Object (readonly)
Returns the value of attribute app.
17 18 19 |
# File 'lib/middleman-core/preview_server.rb', line 17 def app @app end |
.environment ⇒ Object (readonly)
Returns the value of attribute environment.
17 18 19 |
# File 'lib/middleman-core/preview_server.rb', line 17 def environment @environment end |
.server_information ⇒ Object (readonly)
Returns the value of attribute server_information.
17 18 19 |
# File 'lib/middleman-core/preview_server.rb', line 17 def server_information @server_information end |
.ssl_certificate ⇒ Object (readonly)
Returns the value of attribute ssl_certificate.
17 18 19 |
# File 'lib/middleman-core/preview_server.rb', line 17 def ssl_certificate @ssl_certificate end |
.ssl_private_key ⇒ Object (readonly)
Returns the value of attribute ssl_private_key.
17 18 19 |
# File 'lib/middleman-core/preview_server.rb', line 17 def ssl_private_key @ssl_private_key end |
Class Method Details
.reload
This method returns an undefined value.
Simply stop, then start the server
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/middleman-core/preview_server.rb', line 103 def reload app.logger.info '== The Middleman is reloading' begin app = initialize_new_app rescue => e $stderr.puts "Error reloading Middleman: #{e}\n#{e.backtrace.join("\n")}" app.logger.info '== The Middleman is still running the application from before the error' return end unmount_instance @webrick.shutdown @webrick = nil mount_instance(app) app.logger.info '== The Middleman has reloaded' end |
.shutdown
This method returns an undefined value.
Stop the current instance, exit Webrick
126 127 128 129 |
# File 'lib/middleman-core/preview_server.rb', line 126 def shutdown stop @webrick.shutdown end |
.start(opts = {}, cli_options = {})
This method returns an undefined value.
Start an instance of Middleman::Application
21 22 23 24 25 26 27 28 29 30 31 32 33 34 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/middleman-core/preview_server.rb', line 21 def start(opts={}, ={}) # Do not buffer output, otherwise testing of output does not work $stdout.sync = true $stderr.sync = true @options = opts @cli_options = @server_information = ServerInformation.new @server_information.https = (@options[:https] == true) # New app evaluates the middleman configuration. Since this can be # invalid as well, we need to evaluate the configuration BEFORE # checking for validity the_app = initialize_new_app # And now comes the check unless server_information.valid? $stderr.puts %(== Running Middleman failed: #{server_information.reason}. Please fix that and try again.) exit 1 end mount_instance(the_app) app.logger.debug %(== Server information is provided by #{server_information.handler}) app.logger.debug %(== The Middleman is running in "#{environment}" environment) app.logger.debug format('== The Middleman preview server is bound to %s', ServerUrl.new(hosts: server_information.listeners, port: server_information.port, https: server_information.https?).to_bind_addresses.join(', ')) app.logger.info format('== View your site at %s', ServerUrl.new(hosts: server_information.site_addresses, port: server_information.port, https: server_information.https?).to_urls.join(', ')) app.logger.info format('== Inspect your site configuration at %s', ServerUrl.new(hosts: server_information.site_addresses, port: server_information.port, https: server_information.https?).to_config_urls.join(', ')) @initialized ||= false return if @initialized @initialized = true register_signal_handlers # Save the last-used @options so it may be re-used when # reloading later on. ::Middleman::Profiling.report('server_start') app.execute_callbacks(:before_server, [ServerInformationCallbackProxy.new(server_information)]) if @options[:daemon] # To output the child PID, let's make preview server a daemon by hand if child_pid = fork app.logger.info "== Middleman preview server is running in background with PID #{child_pid}" Process.detach child_pid exit 0 else $stdout.reopen('/dev/null', 'w') $stderr.reopen('/dev/null', 'w') $stdin.reopen('/dev/null', 'r') end end loop do @webrick.start # $mm_shutdown is set by the signal handler if $mm_shutdown shutdown exit elsif $mm_reload $mm_reload = false reload end end end |
.stop
This method returns an undefined value.
Detach the current Middleman::Application instance
91 92 93 94 95 96 97 98 99 |
# File 'lib/middleman-core/preview_server.rb', line 91 def stop begin app.logger.info '== The Middleman is shutting down' rescue # if the user closed their terminal STDOUT/STDERR won't exist end unmount_instance end |