From ab831d51764652ec6dbecb510a3fcabc5f1cee97 Mon Sep 17 00:00:00 2001 From: Brett Logan Date: Tue, 12 Mar 2024 22:39:02 -0400 Subject: [PATCH] Re-order middleware to allow /healthz Signed-off-by: Brett Logan --- index.js | 4 +--- src/middleware.js | 5 ++++- src/utils.js | 10 ++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 8c83bd1..30086e4 100644 --- a/index.js +++ b/index.js @@ -13,6 +13,7 @@ import { } from './src/middleware.js' const app = express() +app.get('/healthz', respond) app.use(express.json()) app.use(debugRequest) app.use(hydrateKey) @@ -23,9 +24,6 @@ app.use(verifyGitHubWebhook) app.use(verifyMembership) app.use(verifyCommand) app.use(hydrateOctokit) - -app.get('/', respond) -app.get('/healthz', respond) app.post('/api/github/webhooks', processWebhook) const main = async () => { diff --git a/src/middleware.js b/src/middleware.js index 88e06e4..021a0cc 100644 --- a/src/middleware.js +++ b/src/middleware.js @@ -96,7 +96,10 @@ export const hydrateOctokit = async (req, res, next) => { } export const verifyMembership = async (req, res, next) => { - if (req.body.comment.author_association === 'MEMBER') { + if (req.body.comment.author_association === 'COLLABORATOR' || + req.body.comment.author_association === 'MEMBER' || + req.body.comment.author_association === 'CONTRIBUTOR' || + req.body.comment.author_association === 'OWNER') { return next() } return next('User is not a member') diff --git a/src/utils.js b/src/utils.js index 0202a1e..7d83d33 100644 --- a/src/utils.js +++ b/src/utils.js @@ -7,4 +7,14 @@ export const retrieveRequiredChecks = async (properties) => { } } return requiredChecks +} + +export const unless = function (path, middleware) { + return function (req, res, next) { + if (path === req.path) { + return next(); + } else { + return middleware(req, res, next); + } + }; } \ No newline at end of file