All files / middlewares router.js

92.86% Statements 13/14
66.67% Branches 4/6
100% Functions 1/1
92.86% Lines 13/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31          1x   1x 7x 6x   1x 1x 1x   1x       1x     1x 1x     1x   1x    
/**
 * Middleware to route requests
 **/
'use strict';
 
const assert      = require('assert');
 
module.exports = (app) => {
    if (!app.config.has('routes')) {
        return;
    }
    const config = app.config.get('routes');
    assert(config instanceof Object, 'No routes found');
    assert('string' === typeof config.directory, 'No routing handlers directory found');
 
    Iif (config.routes) {
        app.routes.use(config.routes);
    }
    else {
        app.routes.use(config.directory);
    }
 
    Eif (app.config.has('mvc/proxy/controller')) {
        config.proxy = app.config.get('mvc/proxy/controller');
    }
 
    app.routes.inject(app.router, config);
 
    return app.router.routes();
};