Merge in models and data sources built from config to the app.

This commit is contained in:
Ritchie Martori 2013-05-01 12:34:31 -07:00
parent 6b007fc9e7
commit 7318acb75e
1 changed files with 22 additions and 2 deletions

View File

@ -17,12 +17,32 @@ module.exports = configure;
function configure(root) {
var moduleLoader = configure.createModuleLoader(root);
var app = this;
process.__asteroidCache = {};
return function configureMiddleware(req, res, next) {
req.modules = res.modules = moduleLoader;
moduleLoader.load(next);
var modules = req.modules = res.modules = moduleLoader;
moduleLoader.load(function (err) {
if(err) {
next(err);
} else {
var models = modules.instanceOf('ModelConfiguration');
var dataSources = modules.instanceOf('DataSource');
// define models from config
models.forEach(function (model) {
app.models[model.options.name] = model.ModelCtor;
});
// define data sources from config
dataSources.forEach(function (dataSource) {
app.dataSources[dataSources.options.name] = dataSource;
});
next();
}
});
}
}