Blame view

doraemon/middleware/ifElseMd.js 375 Bytes
htoooth authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19


module.exports = (predict, ifTrueFn, elseFn) => {
    if (!ifTrueFn) {
        ifTrueFn = (req, res, next) => next();
    }

    if (!elseFn) {
        elseFn = (req, res, next) => next();
    }

    return (req, res, next) => {
        if (predict(req, res)) {
            ifTrueFn(req, res, next);
        } else {
            elseFn(req, res, next);
        }
    };
};