From 167e26117afe1cc68dec18a59e34865de9413ad4 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Thu, 12 Mar 2020 13:11:49 +0100 Subject: [PATCH] exceptions with methods --- index.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 1b3b364..6dc45e6 100644 --- a/index.js +++ b/index.js @@ -147,6 +147,20 @@ async function request_handler_authenticate (session, user, key, res, next) { } } +/** + * check if a filter matches a request + * + * @param {any} req request + * @param {any} filter filter + * @returns {boolean} true if filter matches + */ +function filter_matches (req, filter) { + if (filter instanceof RegExp && filter.test (req.url)) + return true; + return req.method === filter.method + && filter.regex + && filter.regex.test (req.url); +} /** * handles http requests @@ -157,8 +171,8 @@ async function request_handler_authenticate (session, user, key, res, next) { */ async function request_handler (req, res, next) { if (Array.isArray (me.ignore_paths)) { - for (const regex of me.ignore_paths) { - if (regex.test (req.url)) { + for (const ignore of me.ignore_paths) { + if (filter_matches (req, ignore)) { next (); return; }