LivelySourceLivelyEnvironmentMiddleware

module Middleware

Shared middleware configuration for Lively application environments.

Provides the application class resolver, asset middleware, and the Lively middleware stack. Included by both module Lively::Environment::HTTP and module Lively::Environment::HTTY environments.

Definitions

def root

Get the root directory for this application.

Signature

returns String

The current working directory.

Implementation

def root
	Dir.pwd
end

def application

Resolve the application class to use.

Signature

returns Class

The application class, either user-defined or default.

Implementation

def application
	if Object.const_defined?(:Application)
		Object.const_get(:Application)
	else
		Console.warn(self, "No Application class defined, using default.")
		::Lively::Application
	end
end

def middleware

Build the middleware stack for this application.

Signature

returns Protocol::HTTP::Middleware

The complete middleware stack.

Implementation

def middleware
	::Protocol::HTTP::Middleware.build do |builder|
		builder.use Lively::Assets, root: File.expand_path("public", self.root)
		builder.use Lively::Assets, root: File.expand_path("../../../public", __dir__)
		builder.use self.application
	end
end