Class: Syntropy::App
- Inherits:
-
Object
- Object
- Syntropy::App
- Defined in:
- lib/syntropy/app.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call(req) ⇒ Object
-
#initialize(machine, src_path, mount_path, opts = {}) ⇒ App
constructor
A new instance of App.
Constructor Details
#initialize(machine, src_path, mount_path, opts = {}) ⇒ App
Returns a new instance of App.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/syntropy/app.rb', line 35 def initialize(machine, src_path, mount_path, opts = {}) @machine = machine @src_path = File.(src_path) @mount_path = mount_path @opts = opts @module_loader = Syntropy::ModuleLoader.new(@src_path, @opts) @router = Syntropy::Router.new(@opts, @module_loader) @machine.spin do # we do startup stuff asynchronously, in order to first let TP2 do its # setup tasks @machine.sleep 0.15 @opts[:logger]&.call("Serving from #{File.(@src_path)}") @router.start_file_watcher if opts[:watch_files] end end |
Class Method Details
.load(opts) ⇒ Object
16 17 18 |
# File 'lib/syntropy/app.rb', line 16 def load(opts) site_file_app(opts) || default_app(opts) end |
Instance Method Details
#call(req) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/syntropy/app.rb', line 53 def call(req) entry = @router[req.path] render_entry(req, entry) rescue Syntropy::Error => e msg = e. req.respond(msg.empty? ? nil : msg, ':status' => e.http_status) rescue StandardError => e p e p e.backtrace req.respond(e., ':status' => Qeweney::Status::INTERNAL_SERVER_ERROR) end |