Class: Fronton::HTMLServer

Inherits:
Object
  • Object
show all
Defined in:
lib/fronton/html_server.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ HTMLServer

Returns a new instance of HTMLServer.



5
6
7
# File 'lib/fronton/html_server.rb', line 5

def initialize(options = {})
  @config = options.fetch(:config)
end

Instance Method Details

#call(env) ⇒ Object

Rack entrypoint



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fronton/html_server.rb', line 10

def call(env)
  if page = requested_page(env) # rubocop:disable Lint/AssignmentInCondition

    if page.exist?
      render_page(page)
    else
      error_404
    end
  else
    fallback = @config.fallback_page

    if fallback
      render_page(fallback)
    else
      error_404
    end
  end
end