Class: Middleman::PreviewServer
- Inherits:
-
Object
- Object
- Middleman::PreviewServer
- 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
Defined Under Namespace
Modules: Checks Classes: AllInterfaces, AllIpv4Interfaces, AllIpv6Interfaces, BasicInformation, BasicServerIpAddress, BindAddressAndServerNameInformation, BindAddressInformation, DefaultInformation, FilteredWebrickLog, NetworkInterfaceInventory, ServerHostname, ServerInformation, 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
- .https? ⇒ Boolean
-
.reload
Simply stop, then start the server.
-
.shutdown
Stop the current instance, exit Webrick.
-
.start(opts = {})
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.
13 14 15 |
# File 'lib/middleman-core/preview_server.rb', line 13 def app @app end |
.environment ⇒ Object (readonly)
Returns the value of attribute environment.
13 14 15 |
# File 'lib/middleman-core/preview_server.rb', line 13 def environment @environment end |
.server_information ⇒ Object (readonly)
Returns the value of attribute server_information.
13 14 15 |
# File 'lib/middleman-core/preview_server.rb', line 13 def server_information @server_information end |
.ssl_certificate ⇒ Object (readonly)
Returns the value of attribute ssl_certificate.
13 14 15 |
# File 'lib/middleman-core/preview_server.rb', line 13 def ssl_certificate @ssl_certificate end |
.ssl_private_key ⇒ Object (readonly)
Returns the value of attribute ssl_private_key.
13 14 15 |
# File 'lib/middleman-core/preview_server.rb', line 13 def ssl_private_key @ssl_private_key end |
Class Method Details
.https? ⇒ Boolean
16 17 18 |
# File 'lib/middleman-core/preview_server.rb', line 16 def https? @https end |
.reload
This method returns an undefined value.
Simply stop, then start the server
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/middleman-core/preview_server.rb', line 91 def reload logger.info '== The Middleman is reloading' begin app = new_app rescue => e logger.error "Error reloading Middleman: #{e}\n#{e.backtrace.join("\n")}" logger.info '== The Middleman is still running the application from before the error' return end unmount_instance @webrick.shutdown @webrick = nil mount_instance(app) logger.info '== The Middleman has reloaded' end |
.shutdown
This method returns an undefined value.
Stop the current instance, exit Webrick
114 115 116 117 |
# File 'lib/middleman-core/preview_server.rb', line 114 def shutdown stop @webrick.shutdown end |
.start(opts = {})
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 |
# File 'lib/middleman-core/preview_server.rb', line 22 def start(opts={}) # Do not buffer output, otherwise testing of output does not work $stdout.sync = true $stderr.sync = true @options = opts @server_information = ServerInformation.new # 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 = new_app # And now comes the check unless server_information.valid? logger.fatal %(== Running Middleman failed: #{server_information.reason}. Please fix that and try again.) exit 1 end mount_instance(the_app) logger.debug %(== Server information is provided by #{server_information.handler}) logger.debug %(== The Middleman is running in "#{environment}" environment) logger.debug format('== The Middleman preview server is bind to %s', ServerUrl.new(hosts: server_information.listeners, port: server_information.port, https: https?).to_bind_addresses.join(', ')) logger.info format('== View your site at %s', ServerUrl.new(hosts: server_information.site_addresses, port: server_information.port, https: https?).to_urls.join(', ')) logger.info format('== Inspect your site configuration at %s', ServerUrl.new(hosts: server_information.site_addresses, port: server_information.port, https: 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') 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
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/middleman-core/preview_server.rb', line 75 def stop begin logger.info '== The Middleman is shutting down' rescue # if the user closed their terminal STDOUT/STDERR won't exist end if @listener @listener.stop @listener = nil end unmount_instance end |