|
1 | 1 | module.exports = lambdaFunction;
|
2 | 2 |
|
3 | 3 | const lowercaseKeys = require("lowercase-keys");
|
| 4 | +const { template } = require("./views/probot"); |
4 | 5 |
|
5 | 6 | async function lambdaFunction(probot, event, context) {
|
6 |
| - try { |
7 |
| - // lowercase all headers to respect headers insensitivity (RFC 7230 $3.2 'Header Fields', see issue #62) |
8 |
| - const headersLowerCase = lowercaseKeys(event.headers); |
9 | 7 |
|
10 |
| - // this will be simpler once we ship `verifyAndParse()` |
11 |
| - // see https://github.com/octokit/webhooks.js/issues/379 |
12 |
| - await probot.webhooks.verifyAndReceive({ |
13 |
| - id: headersLowerCase["x-github-delivery"], |
14 |
| - name: headersLowerCase["x-github-event"], |
15 |
| - signature: |
16 |
| - headersLowerCase["x-hub-signature-256"] || |
17 |
| - headersLowerCase["x-hub-signature"], |
18 |
| - payload: event.body, |
19 |
| - }); |
20 |
| - |
21 |
| - return { |
| 8 | + if (event.httpMethod === "GET" && event.path === "/probot") { |
| 9 | + const res = { |
22 | 10 | statusCode: 200,
|
23 |
| - body: '{"ok":true}', |
24 |
| - }; |
25 |
| - } catch (error) { |
26 |
| - return { |
27 |
| - statusCode: error.status || 500, |
28 |
| - error: "ooops", |
| 11 | + headers: { |
| 12 | + "Content-Type": "text/html", |
| 13 | + }, |
| 14 | + body: template, |
29 | 15 | };
|
| 16 | + return res; |
30 | 17 | }
|
| 18 | + |
| 19 | + // lowercase all headers to respect headers insensitivity (RFC 7230 $3.2 'Header Fields', see issue #62) |
| 20 | + const headersLowerCase = lowercaseKeys(event.headers); |
| 21 | + |
| 22 | + // this will be simpler once we ship `verifyAndParse()` |
| 23 | + // see https://github.com/octokit/webhooks.js/issues/379 |
| 24 | + await probot.webhooks.verifyAndReceive({ |
| 25 | + id: headersLowerCase["x-github-delivery"], |
| 26 | + name: headersLowerCase["x-github-event"], |
| 27 | + signature: |
| 28 | + headersLowerCase["x-hub-signature-256"] || |
| 29 | + headersLowerCase["x-hub-signature"], |
| 30 | + payload: event.body, |
| 31 | + }); |
| 32 | + |
| 33 | + return { |
| 34 | + statusCode: 200, |
| 35 | + body: JSON.stringify({ ok: true }), |
| 36 | + }; |
| 37 | + |
31 | 38 | }
|
0 commit comments