Class: Luna::Server

Inherits:
Async::HTTP::Server
  • Object
show all
Defined in:
lib/luna/server.rb

Overview

HTTP server hosting a middleware stack for static content.

Class Method Summary collapse

Class Method Details

.middleware(root: Dir.pwd, verbose: false, markdown: true, index: "index.html", directory_listing: true) ⇒ Object

Build a middleware for serving static files with optional markdown and logging.

Parameters:

  • root (String) (defaults to: Dir.pwd)

    Root directory for content.

  • verbose (Boolean) (defaults to: false)

    Enable verbose logging.

  • markdown (Boolean) (defaults to: true)

    Enable markdown rendering.

  • index (String) (defaults to: "index.html")

    Index file for directories.

  • directory_listing (Boolean) (defaults to: true)

    Enable basic directory listing when no index exists.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/luna/server.rb', line 23

def self.middleware(root: Dir.pwd, verbose: false, markdown: true, index: "index.html", directory_listing: true)
	::Protocol::HTTP::Middleware.build do
		use Luna::Middleware::Verbose if verbose
		use ::Protocol::HTTP::ContentEncoding
		use Luna::Middleware::Markdown, root: root if markdown
		run Luna::Middleware::Static.new(
			->(request){Protocol::HTTP::Response[404, {"content-type"=>"text/plain"}, ["Not Found"]]},
			root: root,
			index: index,
			directory_listing: directory_listing
		)
	end
end