const router = require('express').Router()
const fs = require('fs')
const logger = require('../../config/logger')

const appsRouters = []
const subApps = fs.readdirSync(__dirname)

subApps.forEach(subAppDir => {
  try {
    const subApp = require(`./${subAppDir}`)

    if (subApp.mountpath) {
      appsRouters.push(router.use(subApp.mountpath, subApp.router))
    } else if (subApp.router) {
      appsRouters.push(router.use(subApp.router))
    } else {
      appsRouters.push(() => {}) // add dummy router as fallback
    }
  } catch (err) {
    logger.warn(err.message)
  }
})

module.exports = appsRouters

const router = require('express').Router()
const fs = require('fs')
const logger = require('../../config/logger')

const appsRouters = []
const subApps = fs.readdirSync(__dirname)

subApps.forEach(subAppDir => {
  try {
    const subApp = require(`./${subAppDir}`)

    if (subApp.mountpath) {
      appsRouters.push(router.use(subApp.mountpath, subApp.router))
    } else if (subApp.router) {
      appsRouters.push(router.use(subApp.router))
    } else {
      appsRouters.push((req, res, next) => next())
    }
  } catch (err) {
    logger.warn(err.message)
  }
})

module.exports = appsRouters

Allow empty router to pass to next middleware
Allow empty router to pass to next middleware

When no router is defined for a feature app the default needs to
just call next to allow the app to pass through.
