• This project
    • Loading...
  • Sign in

fe / yohobuywap-node · Files

Go to a project

GitLab

  • Go to group
  • Project
  • Activity
  • Files
  • Commits
  • Pipelines 0
  • Builds 0
  • Graphs
  • Milestones
  • Issues 0
  • Merge Requests 0
  • Members
  • Labels
  • Wiki
  • Forks
  • Network
  • Create a new issue
  • yohobuywap-node
  • doraemon
  • middleware
  • ifElseMd.js
  • fix add key
    8274b4a6
    by htoooth
    2018-09-13 18:02:20 +0800  
    Browse Files
ifElseMd.js 375 Bytes
Raw Blame History Permalink
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);
        }
    };
};