31 lines
830 B
JavaScript
31 lines
830 B
JavaScript
'use strict';
|
|
|
|
const container = require('./Container');
|
|
const _ = container.get('_');
|
|
const app = container.get('app');
|
|
const path = container.get('path');
|
|
const Controller = container.get('base/Controller');
|
|
const Config = container.get('base/Config');
|
|
|
|
module.exports = (function () {
|
|
const baseRoutePath = path.join(__dirname, 'controllers');
|
|
|
|
// Set up templating
|
|
const view = Config.get('view-engine');
|
|
view.setup(app);
|
|
|
|
// load middleware
|
|
Config.get('middleware').forEach((mw) => app.use(mw));
|
|
|
|
// automatically set up routing by folder structure
|
|
let routeMap = Controller.getRouteMap(baseRoutePath);
|
|
_(routeMap).forEach((routeFunction, routePrefix) => {
|
|
app.use(routePrefix, routeFunction);
|
|
});
|
|
|
|
// load error handlers
|
|
Config.get('error-handlers').forEach((handler) => app.use(handler));
|
|
|
|
return app;
|
|
|
|
}()); |