-
Notifications
You must be signed in to change notification settings - Fork 36
/
lambda-function.js
36 lines (31 loc) · 1.02 KB
/
lambda-function.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
31
32
33
34
35
36
module.exports = lambdaFunction;
const lowercaseKeys = require("lowercase-keys");
const { template } = require("./views/probot");
async function lambdaFunction(probot, event, context) {
if (event.httpMethod === "GET" && event.path === "/probot") {
const res = {
statusCode: 200,
headers: {
"Content-Type": "text/html",
},
body: template,
};
return res;
}
// lowercase all headers to respect headers insensitivity (RFC 7230 $3.2 'Header Fields', see issue #62)
const headersLowerCase = lowercaseKeys(event.headers);
// this will be simpler once we ship `verifyAndParse()`
// see https://github.com/octokit/webhooks.js/issues/379
await probot.webhooks.verifyAndReceive({
id: headersLowerCase["x-github-delivery"],
name: headersLowerCase["x-github-event"],
signature:
headersLowerCase["x-hub-signature-256"] ||
headersLowerCase["x-hub-signature"],
payload: event.body,
});
return {
statusCode: 200,
body: JSON.stringify({ ok: true }),
};
}