Merge in models and data sources built from config to the app.
This commit is contained in:
parent
6b007fc9e7
commit
7318acb75e
|
@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue