forked from civicteam/serverless-offline-direct-lambda
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproxy.js
30 lines (24 loc) · 998 Bytes
/
proxy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const path = require('path');
function handler(event, context, callback) {
// extract the path to the handler (relative to the project root)
// and the function to call on the handler
const [targetHandlerFile, targetHandlerFunction] = event.targetHandler.split(".");
const target = require(path.resolve(__dirname, '../..', event.location, targetHandlerFile));
const headers = event.headers;
if (headers["X-Amz-Invocation-Type"] === "DryRun") {
return;
}
// call the target function
const targetResponse = target[targetHandlerFunction](event.body, context, (error, response) => {
if (headers["X-Amz-Invocation-Type"] === "RequestResponse") {
if (error) {
callback(error)
}
callback(null, JSON.stringify(response))
}
});
if (targetResponse && headers["X-Amz-Invocation-Type"] === "RequestResponse") {
return targetResponse;
}
}
module.exports.handler = handler;