Module: Async::Debug

Defined in:
lib/async/debug.rb,
lib/async/debug/version.rb,
lib/async/debug/reactor_view.rb

Defined Under Namespace

Classes: ReactorView

Constant Summary collapse

SITE_ROOT =

The root directory of the web application files.

File.expand_path("../..", __dir__)
PAGES_ROOT =

The root directory for the utopia middleware.

File.expand_path("pages", SITE_ROOT)
PUBLIC_ROOT =

The root directory for static assets.

File.expand_path("public", SITE_ROOT)
VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.call(builder, root = Dir.pwd, locales: nil, utopia: Utopia.setup) ⇒ Object

Appends a project application to the rack builder.



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
# File 'lib/async/debug.rb', line 62

def self.call(builder, root = Dir.pwd, locales: nil, utopia: Utopia.setup)
  # We want to propate exceptions up when running tests:
  builder.use Rack::ShowExceptions
  
  builder.use Utopia::Static, root: PUBLIC_ROOT
  
  builder.use Utopia::Redirection::Rewrite, {
    '/' => '/index'
  }
  
  builder.use Utopia::Redirection::DirectoryIndex
  
  builder.use Utopia::Redirection::Errors, {
    404 => '/errors/file-not-found'
  }
  
  if locales
    builder.use Utopia::Localization,
      default_locale: locales.first,
      locales: locales
  end
  
  builder.use Utopia::Controller, root: PAGES_ROOT
  builder.use Utopia::Content, root: PAGES_ROOT
  
  builder.run lambda { |env| [404, {}, []] }
end

.serve(endpoint: nil) ⇒ Object

Start the debugger.



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/async/debug.rb', line 35

def self.serve(endpoint: nil)
  endpoint ||= Falcon::Endpoint.parse("https://localhost:9090")
  builder = Rack::Builder.new
  self.call(builder)
  app = builder.to_app
  middleware = Falcon::Server.middleware(app)
  
  Async(transient: true, annotation: self) do
    Console.logger.info(self, "Live debugger binding to #{endpoint}...")
    Async::HTTP::Server.new(middleware, endpoint).run
  end
end