diff --git a/lib/jets/controller/rack/env.rb b/lib/jets/controller/rack/env.rb index 2fc52d9d6..b8a94dd4d 100644 --- a/lib/jets/controller/rack/env.rb +++ b/lib/jets/controller/rack/env.rb @@ -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 diff --git a/spec/fixtures/dumps/api_gateway/books/mounted_list.json b/spec/fixtures/dumps/api_gateway/books/mounted_list.json new file mode 100644 index 000000000..d28c1a753 --- /dev/null +++ b/spec/fixtures/dumps/api_gateway/books/mounted_list.json @@ -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 +} \ No newline at end of file diff --git a/spec/lib/jets/controller/rack/env_spec.rb b/spec/lib/jets/controller/rack/env_spec.rb index 93f1471d7..0606fe159 100644 --- a/spec/lib/jets/controller/rack/env_spec.rb +++ b/spec/lib/jets/controller/rack/env_spec.rb @@ -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