diff --git a/services/auth/server/server.js b/services/auth/server/server.js index f47cadfa0..71e359136 100644 --- a/services/auth/server/server.js +++ b/services/auth/server/server.js @@ -1,5 +1,6 @@ var vnLoopback = require('../../loopback/server/server.js'); -var app = module.exports = vnLoopback(__dirname, true); +var app = module.exports = vnLoopback.loopback(); app.set('applications', require('./application.json')); +vnLoopback.boot(app, __dirname); diff --git a/services/client/server/server.js b/services/client/server/server.js index 257ce195d..1f10f7f51 100644 --- a/services/client/server/server.js +++ b/services/client/server/server.js @@ -1,4 +1,5 @@ var vnLoopback = require('../../loopback/server/server.js'); -module.exports = vnLoopback(__dirname); +var app = module.exports = vnLoopback.loopback(); +vnLoopback.boot(app, __dirname); diff --git a/services/loopback/boot/root.js b/services/loopback/server/boot/root.js similarity index 100% rename from services/loopback/boot/root.js rename to services/loopback/server/boot/root.js diff --git a/services/loopback/boot/validations.js b/services/loopback/server/boot/validations.js similarity index 92% rename from services/loopback/boot/validations.js rename to services/loopback/server/boot/validations.js index 96868a51f..06a8a8c0b 100644 --- a/services/loopback/boot/validations.js +++ b/services/loopback/server/boot/validations.js @@ -1,4 +1,4 @@ -module.exports = function(server) { +module.exports = function(app) { function toJson(object) { let json = {}; @@ -21,9 +21,9 @@ module.exports = function(server) { return json; } - server.get('/validations', function(req, res) { + app.get('/validations', function(req, res) { let json = {}; - let models = server.models; + let models = app.models; for (let modelName in models) { let model = models[modelName]; diff --git a/services/loopback/server/server.js b/services/loopback/server/server.js index 10c214a17..b11c17c58 100644 --- a/services/loopback/server/server.js +++ b/services/loopback/server/server.js @@ -5,29 +5,41 @@ var path = require('path'); var fs = require('fs'); var i18n = require('i18n'); -module.exports = function(rootDir, hasView) -{ - let app = loopback(); +module.exports = { + loopback: loopback, + boot: vnBoot +}; +function vnBoot(app, rootDir, cb) { // Internationalization let i18nDir = rootDir + '/i18n'; - if (fs.existsSync (i18nDir)) { + if (fs.existsSync(i18nDir)) { i18n.configure({ directory: i18nDir, defaultLocale: 'es' }); - app.get('/prueba', function (req,res){ + app.get('/prueba', function(req, res) { i18n.setLocale(req.get('Accept-Language').substring(0,2)); res.send(i18n.__('Hello')); }); } + // View + + let viewDir = path.join(rootDir, '../client'); + + if (fs.existsSync(viewDir)) { + app.set('view engine', 'ejs'); + app.set('views', viewDir); + app.use(loopback.static(path.resolve(rootDir, '../client'))); + } + // Initialization - let packageJson = require(rootDir +'/../package.json'); + let packageJson = require(rootDir + '/../package.json'); let appName = packageJson.name; app.start = function() { @@ -38,12 +50,6 @@ module.exports = function(rootDir, hasView) }); }; - if (hasView) { - app.set('view engine', 'ejs'); - app.set('views', path.join(rootDir, '../client')); - app.use(loopback.static(path.resolve(rootDir, '../client'))); - } - let config = require('./config.json'); for (var key in config) { @@ -57,22 +63,22 @@ module.exports = function(rootDir, hasView) modelSources: [ "loopback/common/models", "loopback/server/models", - __dirname +"/../common/models", - __dirname +"/models", - rootDir +"/../common/models", - rootDir +"/models" + __dirname + "/../common/models", + __dirname + "/models", + rootDir + "/../common/models", + rootDir + "/models" ], mixinDirs: [ "loopback/common/mixins", "loopback/server/mixins", - __dirname +"/../common/mixins", - __dirname +"/mixins", - rootDir +"/../common/mixins", - rootDir +"/mixins" + __dirname + "/../common/mixins", + __dirname + "/mixins", + rootDir + "/../common/mixins", + rootDir + "/mixins" ], bootDirs: [ - __dirname +"/boot", - rootDir +"/boot" + __dirname + "/boot", + rootDir + "/boot" ] }; @@ -80,7 +86,8 @@ module.exports = function(rootDir, hasView) if (err) throw err; if (require.main === module) app.start(); - }); - return app; -}; + if (cb) + cb(app); + }); +} diff --git a/services/production/server/server.js b/services/production/server/server.js index 257ce195d..1f10f7f51 100644 --- a/services/production/server/server.js +++ b/services/production/server/server.js @@ -1,4 +1,5 @@ var vnLoopback = require('../../loopback/server/server.js'); -module.exports = vnLoopback(__dirname); +var app = module.exports = vnLoopback.loopback(); +vnLoopback.boot(app, __dirname); diff --git a/services/route/server/server.js b/services/route/server/server.js index 257ce195d..1f10f7f51 100644 --- a/services/route/server/server.js +++ b/services/route/server/server.js @@ -1,4 +1,5 @@ var vnLoopback = require('../../loopback/server/server.js'); -module.exports = vnLoopback(__dirname); +var app = module.exports = vnLoopback.loopback(); +vnLoopback.boot(app, __dirname); diff --git a/services/salix/server/server.js b/services/salix/server/server.js index d3c1f13df..e67d6aa42 100644 --- a/services/salix/server/server.js +++ b/services/salix/server/server.js @@ -2,10 +2,12 @@ var cookieParser = require('cookie-parser'); var vnLoopback = require('../../loopback/server/server.js'); -var app = module.exports = vnLoopback(__dirname, true); +var app = module.exports = vnLoopback.loopback(); // TODO: ver donde se almacena app.set('api key', 'salix'); app.set('url auth', '/auth'); app.use(cookieParser()); + +vnLoopback.boot(app, __dirname);