-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcustom-integration.js
More file actions
36 lines (30 loc) · 914 Bytes
/
custom-integration.js
File metadata and controls
36 lines (30 loc) · 914 Bytes
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
31
32
33
34
35
36
const { Integration } = require('./integration');
class CustomIntegration extends Integration {
build() {
const payload = this.req.egContext.lambda
|| this.defaultRequestPayload;
return {
FunctionName: this.settings.functionName,
Qualifier: this.settings.qualifier,
Payload: Buffer.from(JSON.stringify(payload))
};
}
respond(payload) {
this.res.statusCode = 200;
this.res.setHeader('Content-Type', this.guessContentType(payload));
this.res.end(payload);
}
get defaultRequestPayload() {
return {
method: this.req.method,
path: this.req.url,
headers: this.req.headers,
body: this.requestBody.toString(this.isBinaryRequestBody ? 'base64' : 'utf8')
}
}
static invoke(options) {
const integration = new CustomIntegration(options);
return integration.invoke();
}
}
module.exports = { CustomIntegration };