Class: Jets::Server::ApiGateway

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/server/api_gateway.rb

Class Method Summary collapse

Class Method Details

.call(env) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/jets/server/api_gateway.rb', line 5

def self.call(env)
  Jets.boot
  route = RouteMatcher.new(env).find_route
  if route
    proxy = LambdaAwsProxy.new(route, env)
    triplet = proxy.response
  else
    [404, {'Content-Type' => 'text/html'}, [routes_error_message(env)]]
  end
end

.routes_error_message(env) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/jets/server/api_gateway.rb', line 16

def self.routes_error_message(env)
  message = "<h2>404 Error: Route #{env['PATH_INFO'].sub('/','')} not found</h2>"
  if Jets.env != "production"
    message << "<p>Here are the routes defined in your application:</p>"
    message << "#{routes_table}"
  end
  message
end

.routes_tableObject

Show pretty route table for user to help with debugging in non-production mode



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/jets/server/api_gateway.rb', line 26

def self.routes_table
  routes = Jets::Router.routes

  return "Your routes table is empty." if routes.empty?

  text = "Verb | Path | Controller#action\n"
  text << "--- | --- | ---\n"
  routes.each do |route|
    text << "#{route.method} | #{route.path} | #{route.to}\n"
  end
  Kramdown::Document.new(text).to_html
end