Class: Volt::Server
Instance Attribute Summary collapse
-
#app_path ⇒ Object
readonly
Returns the value of attribute app_path.
-
#listener ⇒ Object
readonly
Returns the value of attribute listener.
Instance Method Summary collapse
-
#app ⇒ Object
App returns the main rack app.
- #boot_volt ⇒ Object
- #display_welcome ⇒ Object
-
#initialize(root_path = nil, app = nil) ⇒ Server
constructor
You can also optionally pass in a prebooted app.
Constructor Details
#initialize(root_path = nil, app = nil) ⇒ Server
You can also optionally pass in a prebooted app
28 29 30 31 32 33 34 35 |
# File 'lib/volt/server.rb', line 28 def initialize(root_path = nil, app = nil) @root_path = root_path || Dir.pwd @volt_app = app @app_path = File.(File.join(@root_path, 'app')) display_welcome end |
Instance Attribute Details
#app_path ⇒ Object (readonly)
Returns the value of attribute app_path.
25 26 27 |
# File 'lib/volt/server.rb', line 25 def app_path @app_path end |
#listener ⇒ Object (readonly)
Returns the value of attribute listener.
25 26 27 |
# File 'lib/volt/server.rb', line 25 def listener @listener end |
Instance Method Details
#app ⇒ Object
App returns the main rack app. In development it will use ForkingServer, which forks the app and processes responses in a child process, that is killed when code changes and reforked. (This provides simple fast code reloading)
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 |
# File 'lib/volt/server.rb', line 52 def app # Setup the rack server and adaptor RackServerAdaptor.load app = Rack::Builder.new # Handle websocket connections app.use WebsocketHandler can_fork = Process.respond_to?(:fork) unless can_fork Volt.logger.warn('Code reloading in Volt currently depends on `fork`. Your environment does not support `fork`. We\'re working on adding more reloading strategies. For now though you\'ll need to restart the server manually on changes, which sucks. Feel free to complain to the devs, we really let you down here. :-)') end # Only run ForkingServer if fork is supported in this env. # NO_FORKING can be used to specify that you don't want to use the forking # server. if !can_fork || Volt.env.production? || Volt.env.test? || ENV['NO_FORKING'] # In production/test, we boot the app and run the server # # Sometimes the app is already booted, so we can skip if it is boot_volt unless @volt_app # Setup the dispatcher (it stays this class during its run) SocketConnectionHandler.dispatcher = Dispatcher.new(@volt_app) app.run(@volt_app.middleware) else # In developer app.run ForkingServer.new(self) end app end |
#boot_volt ⇒ Object
41 42 43 44 45 46 |
# File 'lib/volt/server.rb', line 41 def boot_volt # Boot the volt app require 'volt/boot' @volt_app ||= Volt.boot(@root_path) end |
#display_welcome ⇒ Object
37 38 39 |
# File 'lib/volt/server.rb', line 37 def display_welcome puts File.read(File.join(File.dirname(__FILE__), 'server/banner.txt')) end |