This repository has been archived on 2018-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
ProgBlog/app/bootstrap.js
2016-02-19 12:58:16 -05:00

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;
}());