Class: Jets::Controller::Rack::Adapter
- Inherits:
-
Object
- Object
- Jets::Controller::Rack::Adapter
- Extended by:
- Memoist
- Defined in:
- lib/jets/controller/rack/adapter.rb
Class Method Summary collapse
-
.process(event, context, meth) ⇒ Object
Returns back API Gateway response hash structure.
Instance Method Summary collapse
-
#convert_to_api_gateway(status, headers, body) ⇒ Object
Transform the structure to AWS_PROXY compatiable structure docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-output-format.
- #env ⇒ Object
-
#initialize(event, context, meth) ⇒ Adapter
constructor
A new instance of Adapter.
-
#process ⇒ Object
1.
-
#rack_vars(vars) ⇒ Object
Called from Jets::Controller::Base.process.
Constructor Details
#initialize(event, context, meth) ⇒ Adapter
Returns a new instance of Adapter.
13 14 15 |
# File 'lib/jets/controller/rack/adapter.rb', line 13 def initialize(event, context, meth) @event, @context, @meth = event, context, meth end |
Class Method Details
.process(event, context, meth) ⇒ Object
Returns back API Gateway response hash structure
8 9 10 11 |
# File 'lib/jets/controller/rack/adapter.rb', line 8 def self.process(event, context, meth) adapter = new(event, context, meth) adapter.process end |
Instance Method Details
#convert_to_api_gateway(status, headers, body) ⇒ Object
Transform the structure to AWS_PROXY compatiable structure docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-output-format
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/jets/controller/rack/adapter.rb', line 32 def convert_to_api_gateway(status, headers, body) base64 = headers["x-jets-base64"] == 'yes' body = body.respond_to?(:read) ? body.read : body body = Base64.encode64(body) if base64 { "statusCode" => status, "headers" => headers, "body" => body, "isBase64Encoded" => base64, } end |
#env ⇒ Object
25 26 27 |
# File 'lib/jets/controller/rack/adapter.rb', line 25 def env Env.new(@event, @context, adapter: true).convert # convert to Rack env end |
#process ⇒ Object
-
Convert API Gateway event event to Rack env
-
Process using full Rack middleware stack
-
Convert back to API gateway response structure payload
20 21 22 23 |
# File 'lib/jets/controller/rack/adapter.rb', line 20 def process status, headers, body = Jets.application.call(env) convert_to_api_gateway(status, headers, body) end |
#rack_vars(vars) ⇒ Object
Called from Jets::Controller::Base.process. Example:
adapter.rack_vars(
'jets.controller' => self,
'lambda.context' => context,
'lambda.event' => event,
'lambda.meth' => meth,
)
Passes a these special variables so we have access to them in the middleware. The controller instance is called in the Main middleware. The lambda.* info is used by the Rack::Local middleware to create a mimicked controller for the local server.
58 59 60 |
# File 'lib/jets/controller/rack/adapter.rb', line 58 def rack_vars(vars) env.merge!(vars) end |