module Async::Debug

Constants

PAGES_ROOT

The root directory for the utopia middleware.

PUBLIC_ROOT

The root directory for static assets.

SITE_ROOT

The root directory of the web application files.

VERSION

Public Class Methods

call(builder, root = Dir.pwd, locales: nil, utopia: Utopia.setup) click to toggle source

Appends a project application to the rack builder.

@parameter builder [Rack::Builder] @parameter root [String] The file-system root path of the project/gem. @parameter locales [Array(String)] an array of locales to support, e.g. `['en', 'ja']`.

# 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) click to toggle source

Start the debugger.

@parameter endpoint [Async::IO::Endpoint] The endpoint to bind to. Defaults to <localhost:9090>.

# 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