Eliminando codigo redundante v5

This commit is contained in:
Juan Ferrer Toribio 2017-10-13 16:54:07 +02:00
parent 8fc14348d7
commit 0962fa19e5
8 changed files with 46 additions and 33 deletions

View File

@ -1,5 +1,6 @@
var vnLoopback = require('../../loopback/server/server.js'); 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')); app.set('applications', require('./application.json'));
vnLoopback.boot(app, __dirname);

View File

@ -1,4 +1,5 @@
var vnLoopback = require('../../loopback/server/server.js'); var vnLoopback = require('../../loopback/server/server.js');
module.exports = vnLoopback(__dirname); var app = module.exports = vnLoopback.loopback();
vnLoopback.boot(app, __dirname);

View File

@ -1,4 +1,4 @@
module.exports = function(server) { module.exports = function(app) {
function toJson(object) { function toJson(object) {
let json = {}; let json = {};
@ -21,9 +21,9 @@ module.exports = function(server) {
return json; return json;
} }
server.get('/validations', function(req, res) { app.get('/validations', function(req, res) {
let json = {}; let json = {};
let models = server.models; let models = app.models;
for (let modelName in models) { for (let modelName in models) {
let model = models[modelName]; let model = models[modelName];

View File

@ -5,29 +5,41 @@ var path = require('path');
var fs = require('fs'); var fs = require('fs');
var i18n = require('i18n'); var i18n = require('i18n');
module.exports = function(rootDir, hasView) module.exports = {
{ loopback: loopback,
let app = loopback(); boot: vnBoot
};
function vnBoot(app, rootDir, cb) {
// Internationalization // Internationalization
let i18nDir = rootDir + '/i18n'; let i18nDir = rootDir + '/i18n';
if (fs.existsSync (i18nDir)) { if (fs.existsSync(i18nDir)) {
i18n.configure({ i18n.configure({
directory: i18nDir, directory: i18nDir,
defaultLocale: 'es' defaultLocale: 'es'
}); });
app.get('/prueba', function (req,res){ app.get('/prueba', function(req, res) {
i18n.setLocale(req.get('Accept-Language').substring(0,2)); i18n.setLocale(req.get('Accept-Language').substring(0,2));
res.send(i18n.__('Hello')); 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 // Initialization
let packageJson = require(rootDir +'/../package.json'); let packageJson = require(rootDir + '/../package.json');
let appName = packageJson.name; let appName = packageJson.name;
app.start = function() { 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'); let config = require('./config.json');
for (var key in config) { for (var key in config) {
@ -57,22 +63,22 @@ module.exports = function(rootDir, hasView)
modelSources: [ modelSources: [
"loopback/common/models", "loopback/common/models",
"loopback/server/models", "loopback/server/models",
__dirname +"/../common/models", __dirname + "/../common/models",
__dirname +"/models", __dirname + "/models",
rootDir +"/../common/models", rootDir + "/../common/models",
rootDir +"/models" rootDir + "/models"
], ],
mixinDirs: [ mixinDirs: [
"loopback/common/mixins", "loopback/common/mixins",
"loopback/server/mixins", "loopback/server/mixins",
__dirname +"/../common/mixins", __dirname + "/../common/mixins",
__dirname +"/mixins", __dirname + "/mixins",
rootDir +"/../common/mixins", rootDir + "/../common/mixins",
rootDir +"/mixins" rootDir + "/mixins"
], ],
bootDirs: [ bootDirs: [
__dirname +"/boot", __dirname + "/boot",
rootDir +"/boot" rootDir + "/boot"
] ]
}; };
@ -80,7 +86,8 @@ module.exports = function(rootDir, hasView)
if (err) throw err; if (err) throw err;
if (require.main === module) if (require.main === module)
app.start(); app.start();
});
return app; if (cb)
}; cb(app);
});
}

View File

@ -1,4 +1,5 @@
var vnLoopback = require('../../loopback/server/server.js'); var vnLoopback = require('../../loopback/server/server.js');
module.exports = vnLoopback(__dirname); var app = module.exports = vnLoopback.loopback();
vnLoopback.boot(app, __dirname);

View File

@ -1,4 +1,5 @@
var vnLoopback = require('../../loopback/server/server.js'); var vnLoopback = require('../../loopback/server/server.js');
module.exports = vnLoopback(__dirname); var app = module.exports = vnLoopback.loopback();
vnLoopback.boot(app, __dirname);

View File

@ -2,10 +2,12 @@
var cookieParser = require('cookie-parser'); var cookieParser = require('cookie-parser');
var vnLoopback = require('../../loopback/server/server.js'); 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 // TODO: ver donde se almacena
app.set('api key', 'salix'); app.set('api key', 'salix');
app.set('url auth', '/auth'); app.set('url auth', '/auth');
app.use(cookieParser()); app.use(cookieParser());
vnLoopback.boot(app, __dirname);