From 21610acfe51a81056201aeac72d4286779a63fc1 Mon Sep 17 00:00:00 2001 From: AJ Schmidt Date: Mon, 9 Jan 2023 18:36:19 -0500 Subject: [PATCH] fix: restore landing page (#111) --- lambda-function.js | 49 ++++++++++++++++++++++++++-------------------- views/probot.js | 1 - 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/lambda-function.js b/lambda-function.js index 90d22f9..483b7b7 100644 --- a/lambda-function.js +++ b/lambda-function.js @@ -1,31 +1,38 @@ module.exports = lambdaFunction; const lowercaseKeys = require("lowercase-keys"); +const { template } = require("./views/probot"); 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); - // 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 { + if (event.httpMethod === "GET" && event.path === "/probot") { + const res = { statusCode: 200, - body: '{"ok":true}', - }; - } catch (error) { - return { - statusCode: error.status || 500, - error: "ooops", + 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 }), + }; + } 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?

Documentation - Chat on Slack