Class: Middleman::PreviewServer
- Inherits:
-
Object
- Object
- Middleman::PreviewServer
- Extended by:
- Forwardable
- Defined in:
- middleman-core/lib/middleman-core/preview_server.rb,
middleman-core/lib/middleman-core/preview_server/checks.rb,
middleman-core/lib/middleman-core/preview_server/server_url.rb,
middleman-core/lib/middleman-core/preview_server/information.rb,
middleman-core/lib/middleman-core/preview_server/server_hostname.rb,
middleman-core/lib/middleman-core/preview_server/tcp_port_prober.rb,
middleman-core/lib/middleman-core/preview_server/server_ip_address.rb,
middleman-core/lib/middleman-core/preview_server/server_information.rb,
middleman-core/lib/middleman-core/preview_server/network_interface_inventory.rb,
middleman-core/lib/middleman-core/preview_server/server_information_validator.rb,
middleman-core/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(options_hash = ::Middleman::EMPTY_HASH, cli_options_hash = ::Middleman::EMPTY_HASH)
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
18 19 20 |
# File 'middleman-core/lib/middleman-core/preview_server.rb', line 18 def app @app end |
.environment ⇒ Object (readonly)
Returns the value of attribute environment
18 19 20 |
# File 'middleman-core/lib/middleman-core/preview_server.rb', line 18 def environment @environment end |
.server_information ⇒ Object (readonly)
Returns the value of attribute server_information
18 19 20 |
# File 'middleman-core/lib/middleman-core/preview_server.rb', line 18 def server_information @server_information end |
.ssl_certificate ⇒ Object (readonly)
Returns the value of attribute ssl_certificate
18 19 20 |
# File 'middleman-core/lib/middleman-core/preview_server.rb', line 18 def ssl_certificate @ssl_certificate end |
.ssl_private_key ⇒ Object (readonly)
Returns the value of attribute ssl_private_key
18 19 20 |
# File 'middleman-core/lib/middleman-core/preview_server.rb', line 18 def ssl_private_key @ssl_private_key end |
Class Method Details
.reload
This method returns an undefined value.
Simply stop, then start the server
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'middleman-core/lib/middleman-core/preview_server.rb', line 107 def reload app.logger.info '== The Middleman is reloading' app.execute_callbacks(:reload) begin app = initialize_new_app rescue StandardError => e warn "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
132 133 134 135 |
# File 'middleman-core/lib/middleman-core/preview_server.rb', line 132 def shutdown stop @webrick.shutdown end |
.start(options_hash = ::Middleman::EMPTY_HASH, cli_options_hash = ::Middleman::EMPTY_HASH)
This method returns an undefined value.
Start an instance of Middleman::Application
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 88 89 90 91 |
# File 'middleman-core/lib/middleman-core/preview_server.rb', line 22 def start( = ::Middleman::EMPTY_HASH, = ::Middleman::EMPTY_HASH) # Do not buffer output, otherwise testing of output does not work $stdout.sync = true $stderr.sync = true @options = @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? warn %(== 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 %<url>s', url: 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 %<url>s', url: 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 %<url>s', url: 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 child_pid = fork if child_pid 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
95 96 97 98 99 100 101 102 103 |
# File 'middleman-core/lib/middleman-core/preview_server.rb', line 95 def stop begin app.logger.info '== The Middleman is shutting down' rescue StandardError # if the user closed their terminal STDOUT/STDERR won't exist end unmount_instance end |