lambda-request-handler
Advanced tools
Comparing version 0.2.1 to 0.2.2
@@ -27,2 +27,3 @@ "use strict"; | ||
let ssl = false; | ||
const queryStringParams = getValuesFromStringAndMultiString(event.queryStringParameters, event.multiValueQueryStringParameters); | ||
const headers = getValuesFromStringAndMultiString(event.headers, event.multiValueHeaders); | ||
@@ -32,10 +33,8 @@ if (ctx) { | ||
} | ||
const queryStringParams = getValuesFromStringAndMultiString(event.queryStringParameters, event.multiValueQueryStringParameters); | ||
if (event.requestContext && event.requestContext.elb) { | ||
//load balancer request - it has the client ip in x-forwarded-for header | ||
if (typeof headers['x-forwarded-for'] === 'string') { | ||
const ips = headers['x-forwarded-for'].split(' '); | ||
remoteAddress = ips[ips.length - 1]; | ||
ips.splice(-1, 1); | ||
headers['x-forwarded-for'] = ips.join(' '); | ||
const ips = headers['x-forwarded-for'].split(',').map(ip => ip.trim()); | ||
remoteAddress = ips.splice(-1, 1)[0]; | ||
headers['x-forwarded-for'] = ips.join(', '); | ||
ssl = headers['x-forwarded-proto'] === 'https'; | ||
@@ -48,3 +47,3 @@ if (ips.length === 0) { | ||
} | ||
//elb also doesn't uri decode query string params | ||
//elb doesn't uri decode query string params | ||
Object.keys(queryStringParams).forEach(k => { | ||
@@ -51,0 +50,0 @@ queryStringParams[k] = decodeURIComponent(queryStringParams[k]); |
@@ -19,19 +19,18 @@ "use strict"; | ||
return _p | ||
.then(app => { | ||
return Promise.resolve() | ||
.then(() => { | ||
const reqOptions = eventToRequestOptions_1.default(event, ctx); | ||
const appHandler = in_process_request_1.default(app); | ||
return appHandler(reqOptions); | ||
}) | ||
.then(res => response_1.inProcessResponseToLambdaResponse(res, eventWithMultiValueHeaders(event))) | ||
.catch(e => { | ||
console.error(e); | ||
return response_1.errorResponse(); | ||
}); | ||
}); | ||
.then(app => processRequest(app, event, ctx)); | ||
}; | ||
}; | ||
const processRequest = (app, event, ctx) => Promise.resolve() | ||
.then(() => { | ||
const reqOptions = eventToRequestOptions_1.default(event, ctx); | ||
const appHandler = in_process_request_1.default(app); | ||
return appHandler(reqOptions); | ||
}) | ||
.then(res => response_1.inProcessResponseToLambdaResponse(res, eventWithMultiValueHeaders(event))) | ||
.catch(e => { | ||
console.error(e); | ||
return response_1.errorResponse(); | ||
}); | ||
const handler = (app) => handlerPromise(() => Promise.resolve(app)); | ||
handler.deferred = handlerPromise; | ||
module.exports = handler; |
{ | ||
"name": "lambda-request-handler", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"license": "(MIT OR Apache-2.0)", | ||
@@ -32,3 +32,3 @@ "scripts": { | ||
"dependencies": { | ||
"in-process-request": "^0.0.6" | ||
"in-process-request": "^0.0.7" | ||
}, | ||
@@ -35,0 +35,0 @@ "devDependencies": { |
@@ -10,2 +10,3 @@ # lambda-request-handler | ||
* Express.js v4 | ||
* Express.js v5 | ||
* Connect v3 | ||
@@ -12,0 +13,0 @@ * Koa v2 |
93
20786
260
+ Addedin-process-request@0.0.7(transitive)
- Removedin-process-request@0.0.6(transitive)
Updatedin-process-request@^0.0.7