Skip to content

Commit

Permalink
Merge pull request rubyonjets#598 from wurlinc/fix-mount
Browse files Browse the repository at this point in the history
fixing issues when mounting
  • Loading branch information
tongueroo authored Oct 19, 2021
2 parents 5247405 + 4cee6fe commit bf6498f
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/jets/controller/rack/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def path_with_base_path
if(!pathParameters.nil? and !resource.nil?)
resource = pathParameters.reduce(resource) {|resource, parameter|
key, value = parameter
key = key.eql?("catchall") ? "{#{key}+}" : "{#{key}}"
resource = resource.gsub(key, value)
resource = resource.gsub("{#{key}+}", value)
resource = resource.gsub("{#{key}}", value)
resource
}
end
Expand Down
58 changes: 58 additions & 0 deletions spec/fixtures/dumps/api_gateway/books/mounted_list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"resource": "/mount/{path+}",
"path": "/mount/books/list",
"httpMethod": "GET",
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"cache-control": "no-cache",
"CloudFront-Forwarded-Proto": "https",
"CloudFront-Is-Desktop-Viewer": "true",
"CloudFront-Is-Mobile-Viewer": "false",
"CloudFront-Is-SmartTV-Viewer": "false",
"CloudFront-Is-Tablet-Viewer": "false",
"CloudFront-Viewer-Country": "US",
"Content-Type": "text/plain",
"Host": "uhghn8z6t1.execute-api.us-east-1.amazonaws.com",
"Postman-Token": "7166b11b-59de-4e7b-ad35-24e556b7a083",
"User-Agent": "PostmanRuntime/6.4.1",
"Via": "1.1 55676da1e5c0a9c4e60a94a95b01dc04.cloudfront.net (CloudFront)",
"X-Amz-Cf-Id": "iERhUw6ghRnv1uRYfxJaUsDGWVbERFSZ4K00CIgZtJ0T6yeFdItMeQ==",
"X-Amzn-Trace-Id": "Root=1-59f50229-587ec5271678236e50ad91b1",
"X-Forwarded-For": "69.42.1.180, 54.239.203.100",
"X-Forwarded-Port": "443",
"X-Forwarded-Proto": "https"
},
"queryStringParameters": {
"a": "1",
"b": "2"
},
"pathParameters": {"path": "books/list"},
"stageVariables": null,
"requestContext": {
"path": "/stag/books",
"accountId": "123456789012",
"resourceId": "c0yhg8",
"stage": "stag",
"requestId": "e5c39604-bc2d-11e7-abbe-1baaa0f8e02e",
"identity": {
"cognitoIdentityPoolId": null,
"accountId": null,
"cognitoIdentityId": null,
"caller": null,
"apiKey": "",
"sourceIp": "69.42.1.180",
"accessKey": null,
"cognitoAuthenticationType": null,
"cognitoAuthenticationProvider": null,
"userArn": null,
"userAgent": "PostmanRuntime/6.4.1",
"user": null
},
"resourcePath": "/books/list",
"httpMethod": "GET",
"apiId": "uhghn8z6t1"
},
"body": "{\n \"key3\": \"value3\",\n \"key2\": \"value2\",\n \"key1\": \"value1\"\n}",
"isBase64Encoded": false
}
17 changes: 17 additions & 0 deletions spec/lib/jets/controller/rack/env_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@
end
end

context "mount" do
let(:event) { json_file("spec/fixtures/dumps/api_gateway/books/mounted_list.json") }
it "convert" do
env = rack_env.convert
# pp env # uncomment to debug
expect(env).to be_a(Hash)
expect(env['REQUEST_METHOD']).to eq "GET"
expect(env['SERVER_NAME']).to eq("uhghn8z6t1.execute-api.us-east-1.amazonaws.com")
expect(env['QUERY_STRING']).to eq("a=1&b=2")
expect(env['PATH_INFO']).to eq("/mount/books/list")
expect(env['REMOTE_ADDR']).to eq("69.42.1.180, 54.239.203.100")
expect(env['REQUEST_URI']).to eq("https://uhghn8z6t1.execute-api.us-east-1.amazonaws.com/mount/books/list?a=1&b=2")
expect(env['HTTP_USER_AGENT']).to eq("PostmanRuntime/6.4.1")
expect(env["rack.input"]).not_to be nil
end
end

context "empty body" do
let(:event) { json_file("spec/fixtures/dumps/api_gateway/posts/show.json") }
it "convert" do
Expand Down

0 comments on commit bf6498f

Please sign in to comment.