From 33c654c7c5f0d446857c730574611fc19d817c98 Mon Sep 17 00:00:00 2001 From: AJ Schmidt Date: Tue, 8 Mar 2022 21:19:24 -0500 Subject: [PATCH 1/5] Fix error response The `error` field is not valid for an API Gateway response. As noted in the AWS docs below, when an error response contains invalid fields, it will always return a `502` error code with a body of `{"message": "Internal server error"}`. This PR updates the error response fields to contain valid fields and a more sensible response message. - https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html#services-apigateway-errors --- lambda-function.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambda-function.js b/lambda-function.js index 90d22f9..f72ff1e 100644 --- a/lambda-function.js +++ b/lambda-function.js @@ -25,7 +25,7 @@ async function lambdaFunction(probot, event, context) { } catch (error) { return { statusCode: error.status || 500, - error: "ooops", + body: "Error processing GitHub Event", }; } } From 193136b872d613c6f9ada4b98af36f4ec86e9cc2 Mon Sep 17 00:00:00 2001 From: AJ Schmidt Date: Thu, 22 Dec 2022 13:46:24 -0500 Subject: [PATCH 2/5] rm `try`/`catch` block --- lambda-function.js | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/lambda-function.js b/lambda-function.js index f72ff1e..f497af8 100644 --- a/lambda-function.js +++ b/lambda-function.js @@ -3,29 +3,23 @@ module.exports = lambdaFunction; const lowercaseKeys = require("lowercase-keys"); async function lambdaFunction(probot, event, context) { - try { - // lowercase all headers to respect headers insensitivity (RFC 7230 $3.2 'Header Fields', see issue #62) - const headersLowerCase = lowercaseKeys(event.headers); + // 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, - }); + // 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: '{"ok":true}', + }; - return { - statusCode: 200, - body: '{"ok":true}', - }; - } catch (error) { - return { - statusCode: error.status || 500, - body: "Error processing GitHub Event", - }; - } } From 70dcf4d95f54b130e54928a43ec1ddb4825f47f6 Mon Sep 17 00:00:00 2001 From: AJ Schmidt Date: Thu, 22 Dec 2022 13:46:48 -0500 Subject: [PATCH 3/5] use `JSON.stringify()` --- lambda-function.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambda-function.js b/lambda-function.js index f497af8..225e4f2 100644 --- a/lambda-function.js +++ b/lambda-function.js @@ -19,7 +19,7 @@ async function lambdaFunction(probot, event, context) { return { statusCode: 200, - body: '{"ok":true}', + body: JSON.stringify({ ok: true }), }; } From f56bf47d245c417e53f1e98d6ba0b5e330254c79 Mon Sep 17 00:00:00 2001 From: AJ Schmidt Date: Thu, 22 Dec 2022 16:48:31 -0500 Subject: [PATCH 4/5] restore landing page functionality --- lambda-function.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lambda-function.js b/lambda-function.js index 225e4f2..483b7b7 100644 --- a/lambda-function.js +++ b/lambda-function.js @@ -1,8 +1,21 @@ 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); From 291cc5a23c6219e6fa926f4c988f01fa4bc14e2b Mon Sep 17 00:00:00 2001 From: AJ Schmidt Date: Thu, 22 Dec 2022 16:48:37 -0500 Subject: [PATCH 5/5] rm dead link --- views/probot.js | 1 - 1 file changed, 1 deletion(-) diff --git a/views/probot.js b/views/probot.js index 9a46ce4..4d4cfa3 100644 --- a/views/probot.js +++ b/views/probot.js @@ -25,7 +25,6 @@ module.exports.template = `

Need help?