exceptions with methods

This commit is contained in:
Timo Hocker 2020-03-12 13:11:49 +01:00
parent 2a3d5b4425
commit 167e26117a

View File

@ -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 * handles http requests
@ -157,8 +171,8 @@ async function request_handler_authenticate (session, user, key, res, next) {
*/ */
async function request_handler (req, res, next) { async function request_handler (req, res, next) {
if (Array.isArray (me.ignore_paths)) { if (Array.isArray (me.ignore_paths)) {
for (const regex of me.ignore_paths) { for (const ignore of me.ignore_paths) {
if (regex.test (req.url)) { if (filter_matches (req, ignore)) {
next (); next ();
return; return;
} }