aws-serverless-express
Advanced tools
Comparing version 1.1.3 to 1.1.4
52
index.js
@@ -29,13 +29,16 @@ /* | ||
function mapApiGatewayEventToHttpRequest(event, context, socketPath) { | ||
event.headers['x-apigateway-event'] = JSON.stringify(event) | ||
event.headers['x-apigateway-context'] = JSON.stringify(context) | ||
const headers = event.headers || {} | ||
headers['x-apigateway-event'] = JSON.stringify(event) | ||
headers['x-apigateway-context'] = JSON.stringify(context) | ||
return { | ||
method: event.httpMethod, | ||
path: getPathWithQueryStringParams(event), | ||
headers: event.headers, | ||
socketPath: socketPath, | ||
// protocol: `${event.headers['X-Forwarded-Proto']}:`, | ||
// host: event.headers.Host, | ||
// hostname: event.headers.Host, // Alias for host | ||
// port: event.headers['X-Forwarded-Port'] | ||
headers, | ||
socketPath | ||
// protocol: `${headers['X-Forwarded-Proto']}:`, | ||
// host: headers.Host, | ||
// hostname: headers.Host, // Alias for host | ||
// port: headers['X-Forwarded-Port'] | ||
} | ||
@@ -64,3 +67,3 @@ } | ||
function forwardConnectionErrorResponseToApiGateway(server, error, context) { | ||
// if debug: console.log(error) | ||
console.error(error) | ||
const errorResponse = { | ||
@@ -75,2 +78,13 @@ statusCode: 502, // "DNS resolution, TCP level errors, or actual HTTP parse errors" - https://nodejs.org/api/http.html#http_http_request_options_callback | ||
function forwardLibraryErrorResponseToApiGateway(server, error, context) { | ||
console.error(error) | ||
const errorResponse = { | ||
statusCode: 500, | ||
body: '', | ||
headers: {} | ||
} | ||
context.succeed(errorResponse) | ||
} | ||
function forwardRequestToNodeServer(server, event, context) { | ||
@@ -120,8 +134,18 @@ const requestOptions = mapApiGatewayEventToHttpRequest(event, context, getSocketPath(server._socketPathSuffix)) | ||
exports.proxy = (server, event, context) => { | ||
if (server._isListening) { | ||
forwardRequestToNodeServer(server, event, context) | ||
} else { | ||
startServer(server) | ||
.on('listening', () => forwardRequestToNodeServer(server, event, context)) | ||
try { | ||
if (server._isListening) { | ||
forwardRequestToNodeServer(server, event, context) | ||
} else { | ||
startServer(server) | ||
.on('listening', () => { | ||
try { | ||
forwardRequestToNodeServer(server, event, context) | ||
} catch(error) { | ||
forwardLibraryErrorResponseToApiGateway(server, error, context) | ||
} | ||
}) | ||
} | ||
} catch (error) { | ||
forwardLibraryErrorResponseToApiGateway(server, error, context) | ||
} | ||
} |
{ | ||
"name": "aws-serverless-express", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "This library enables you to utilize AWS Lambda and Amazon API Gateway to respond to web and API requests using your existing Node.js application framework.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27082
141