Skip to content

beforeRouter/afterRouter not needed to be validated for isArray #34

@killmenot

Description

@killmenot

Hi @robtweed

Please consider the following lines:

qewd/lib/master-express.js

Lines 95 to 102 in cbf87ac

var options = {
nextCallback: route.afterRouter ? true : false
};
args = args.concat([qx.router(options)]);
// add array with custom middleware to add after qx.router is called (if present)
if (route.afterRouter && Array.isArray(route.afterRouter)) args = args.concat(route.afterRouter);

Some notes:

  1. I'm not sure that beforeRouter/afterRouter must be validated to be an array because concat works fine if passed argument can be added to existing array -> [1, 2].concat(3) => [1, 2, 3]
  2. Another note is that, if we keep the current structure and declare beforeRouter/afterRouter as NOT an array, nextCallback can be set incorrectly (it will be true) but afterRouter won't be added

My proposal here is to allow developers to pass afterRouter as function of array of functions. In this case we do not need to validate beforeRouter/afterRouter for Array.isArray

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions