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 app = module.exports = vnLoopback(__dirname, true);
var app = module.exports = vnLoopback.loopback();
app.set('applications', require('./application.json'));
vnLoopback.boot(app, __dirname);

View File

@ -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);

View File

@ -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];

View File

@ -5,10 +5,12 @@ 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';
@ -25,6 +27,16 @@ module.exports = function(rootDir, hasView)
});
}
// 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');
@ -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) {
@ -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);
});
}

View File

@ -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);

View File

@ -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);

View File

@ -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);