2017-10-13 14:22:45 +00:00
|
|
|
|
|
|
|
var loopback = require('loopback');
|
|
|
|
var boot = require('loopback-boot');
|
|
|
|
var path = require('path');
|
|
|
|
var fs = require('fs');
|
|
|
|
var i18n = require('i18n');
|
|
|
|
|
2017-10-13 14:54:07 +00:00
|
|
|
module.exports = {
|
|
|
|
loopback: loopback,
|
|
|
|
boot: vnBoot
|
|
|
|
};
|
2017-10-13 14:22:45 +00:00
|
|
|
|
2017-10-13 14:54:07 +00:00
|
|
|
function vnBoot(app, rootDir, cb) {
|
2017-10-13 14:22:45 +00:00
|
|
|
// Internationalization
|
|
|
|
|
|
|
|
let i18nDir = rootDir + '/i18n';
|
|
|
|
|
2017-10-13 14:54:07 +00:00
|
|
|
if (fs.existsSync(i18nDir)) {
|
2017-10-13 14:22:45 +00:00
|
|
|
i18n.configure({
|
|
|
|
directory: i18nDir,
|
|
|
|
defaultLocale: 'es'
|
|
|
|
});
|
|
|
|
|
2017-10-13 14:54:07 +00:00
|
|
|
app.get('/prueba', function(req, res) {
|
2017-10-13 14:22:45 +00:00
|
|
|
i18n.setLocale(req.get('Accept-Language').substring(0,2));
|
|
|
|
res.send(i18n.__('Hello'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-13 14:54:07 +00:00
|
|
|
// 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')));
|
|
|
|
}
|
|
|
|
|
2017-10-13 14:22:45 +00:00
|
|
|
// Initialization
|
|
|
|
|
2017-10-13 14:54:07 +00:00
|
|
|
let packageJson = require(rootDir + '/../package.json');
|
2017-10-13 14:22:45 +00:00
|
|
|
let appName = packageJson.name;
|
|
|
|
|
|
|
|
app.start = function() {
|
|
|
|
return app.listen(function() {
|
|
|
|
app.emit('started');
|
|
|
|
var baseUrl = app.get('url').replace(/\/$/, '');
|
|
|
|
console.log(`Web server ${appName} listening at: %s`, baseUrl);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
let config = require('./config.json');
|
|
|
|
|
|
|
|
for (var key in config) {
|
|
|
|
app.set(key, config[key]);
|
|
|
|
}
|
|
|
|
|
|
|
|
var bootOptions = {
|
|
|
|
appRootDir: __dirname,
|
|
|
|
appConfigRootDir: rootDir,
|
|
|
|
modelsRootDir: rootDir,
|
|
|
|
modelSources: [
|
|
|
|
"loopback/common/models",
|
|
|
|
"loopback/server/models",
|
2017-10-13 14:54:07 +00:00
|
|
|
__dirname + "/../common/models",
|
|
|
|
__dirname + "/models",
|
|
|
|
rootDir + "/../common/models",
|
|
|
|
rootDir + "/models"
|
2017-10-13 14:22:45 +00:00
|
|
|
],
|
|
|
|
mixinDirs: [
|
|
|
|
"loopback/common/mixins",
|
|
|
|
"loopback/server/mixins",
|
2017-10-13 14:54:07 +00:00
|
|
|
__dirname + "/../common/mixins",
|
|
|
|
__dirname + "/mixins",
|
|
|
|
rootDir + "/../common/mixins",
|
|
|
|
rootDir + "/mixins"
|
2017-10-13 14:22:45 +00:00
|
|
|
],
|
|
|
|
bootDirs: [
|
2017-10-13 14:54:07 +00:00
|
|
|
__dirname + "/boot",
|
|
|
|
rootDir + "/boot"
|
2017-10-13 14:22:45 +00:00
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
boot(app, bootOptions, function(err) {
|
|
|
|
if (err) throw err;
|
|
|
|
if (require.main === module)
|
|
|
|
app.start();
|
|
|
|
|
2017-10-13 14:54:07 +00:00
|
|
|
if (cb)
|
|
|
|
cb(app);
|
|
|
|
});
|
|
|
|
}
|