#814 Services unified with karma & e2e tests working
This commit is contained in:
parent
5d84e51639
commit
87dec5e8b2
|
@ -0,0 +1,8 @@
|
|||
FROM node:8-slim
|
||||
|
||||
COPY . /salix
|
||||
COPY dist/webpack-assets.json /salix/client/
|
||||
|
||||
RUN npm -g install pm2
|
||||
WORKDIR /salix
|
||||
CMD ["pm2-docker", "./server/server.js"]
|
|
@ -36,16 +36,18 @@ export default class Controller {
|
|||
token: data.token,
|
||||
continue: data.continue
|
||||
};
|
||||
this.$window.location = `${data.loginUrl}?${this.encodeUri(params)}`;
|
||||
let loginUrl = data.loginUrl || '';
|
||||
this.$window.location = `${loginUrl}?${this.encodeUri(params)}`;
|
||||
}
|
||||
encodeUri(object) {
|
||||
let uri = '';
|
||||
for (var key in object)
|
||||
if (object[key]) {
|
||||
for (let key in object) {
|
||||
if (object[key] !== undefined) {
|
||||
if (uri.length > 0)
|
||||
uri += '&';
|
||||
uri += encodeURIComponent(key) + '=' + encodeURIComponent(object[key]);
|
||||
}
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
onLoginErr(json) {
|
||||
|
|
|
@ -20,18 +20,19 @@ export default class MainMenu {
|
|||
this.modules = modulesFactory.getModules();
|
||||
this.langs = [];
|
||||
|
||||
for (var code of $translate.getAvailableLanguageKeys())
|
||||
for (let code of $translate.getAvailableLanguageKeys()) {
|
||||
this.langs.push({
|
||||
code: code,
|
||||
name: languages[code] ? languages[code] : code
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
getCurrentUserName() {
|
||||
this.$http.get('/auth/api/Accounts/getCurrentUserName')
|
||||
.then(json => {
|
||||
this.$.currentUserName = json.data;
|
||||
});
|
||||
this.$http.get('/api/Accounts/getCurrentUserName')
|
||||
.then(json => {
|
||||
this.$.currentUserName = json.data;
|
||||
});
|
||||
}
|
||||
|
||||
openUserConfiguration(event) {
|
||||
|
|
|
@ -4,21 +4,18 @@ describe('Component vnMainMenu', () => {
|
|||
let $httpBackend;
|
||||
let controller;
|
||||
|
||||
beforeEach(() => {
|
||||
angular.mock.module('salix');
|
||||
});
|
||||
beforeEach(ngModule('salix'));
|
||||
|
||||
beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_) => {
|
||||
let modulesFactory = {getModules: () => {}};
|
||||
$httpBackend = _$httpBackend_;
|
||||
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
||||
controller = _$componentController_('vnMainMenu', {modulesFactory: modulesFactory});
|
||||
}));
|
||||
|
||||
describe('getCurrentUserName()', () => {
|
||||
it(`should set the user name property in the controller`, () => {
|
||||
$httpBackend.when('GET', `/auth/api/Accounts/getCurrentUserName`).respond('Batman');
|
||||
$httpBackend.expect('GET', `/auth/api/Accounts/getCurrentUserName`);
|
||||
$httpBackend.when('GET', `/api/Accounts/getCurrentUserName`).respond('Batman');
|
||||
$httpBackend.expect('GET', `/api/Accounts/getCurrentUserName`);
|
||||
controller.getCurrentUserName();
|
||||
$httpBackend.flush();
|
||||
|
||||
|
|
51
gulpfile.js
51
gulpfile.js
|
@ -19,6 +19,7 @@ let env = process.env.NODE_ENV ? process.env.NODE_ENV : 'development';
|
|||
let langs = ['es', 'en'];
|
||||
let srcDir = './client';
|
||||
let servicesDir = './services';
|
||||
let services = require('./services/services.yml');
|
||||
|
||||
let wpConfig = require('./webpack.config.yml');
|
||||
let buildDir = wpConfig.buildDir;
|
||||
|
@ -37,7 +38,7 @@ let defaultPort = proxyConf.defaultPort;
|
|||
// Development
|
||||
|
||||
gulp.task('default', () => {
|
||||
return gulp.start('services', 'client');
|
||||
return gulp.start('client', 'services');
|
||||
});
|
||||
|
||||
gulp.task('client', ['build-clean'], async () => {
|
||||
|
@ -54,10 +55,10 @@ gulp.task('services', async () => {
|
|||
/**
|
||||
* Starts backend services.
|
||||
*/
|
||||
gulp.task('services-only', async () => {
|
||||
const services = await getServices();
|
||||
for (let service of services)
|
||||
require(service.index).start(service.port);
|
||||
gulp.task('services-only', callback => {
|
||||
let app = require(`./services/loopback/server/server`);
|
||||
app.start(defaultPort);
|
||||
app.on('started', callback);
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -148,7 +149,6 @@ gulp.task('docker-compose', async () => {
|
|||
|
||||
let compose = await fs.readFile('./docker-compose.tpl.yml', 'utf8');
|
||||
let composeYml = yaml.safeLoad(compose);
|
||||
let services = await getServices();
|
||||
|
||||
let imageTag = 'latest';
|
||||
if (process.env.BUILD_NUMBER)
|
||||
|
@ -160,12 +160,12 @@ gulp.task('docker-compose', async () => {
|
|||
|
||||
for (let service of services) {
|
||||
let dockerFile = `Dockerfile`;
|
||||
let localDockerFile = `${__dirname}/services/${service.name}/Dockerfile`;
|
||||
let localDockerFile = `${__dirname}/services/${service}/Dockerfile`;
|
||||
|
||||
if (await fs.exists(localDockerFile))
|
||||
dockerFile = localDockerFile;
|
||||
|
||||
composeYml.services[service.name] = {
|
||||
composeYml.services[service] = {
|
||||
build: {
|
||||
context: `./services`,
|
||||
dockerfile: dockerFile
|
||||
|
@ -177,7 +177,7 @@ gulp.task('docker-compose', async () => {
|
|||
};
|
||||
|
||||
composeYml.services.nginx.links.push(
|
||||
`${service.name}:${namePrefix}${service.name}`
|
||||
`${service}:${namePrefix}${service}`
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -216,7 +216,7 @@ let nginxTemp = `${nginxDir}/temp`;
|
|||
* Starts the nginx process, if it is started, restarts it.
|
||||
*/
|
||||
gulp.task('nginx', async () => {
|
||||
await runSequenceP('nginx-stop', 'nginx-start');
|
||||
await runSequenceP('nginx-start');
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -228,7 +228,7 @@ gulp.task('nginx-start', ['nginx-conf'], async () => {
|
|||
if (isWindows)
|
||||
nginxBin = `start /B ${nginxBin}`;
|
||||
|
||||
log(`Application will be available at http://${proxyConf.host}:${proxyConf.port}/`);
|
||||
log(`Application available at http://${proxyConf.host}:${proxyConf.port}/`);
|
||||
await execP(`${nginxBin} -c "${nginxConf}" -p "${nginxDir}"`);
|
||||
});
|
||||
|
||||
|
@ -255,7 +255,7 @@ gulp.task('nginx-conf', ['nginx-stop'], async () => {
|
|||
await fs.mkdir(nginxTemp);
|
||||
|
||||
let params = {
|
||||
services: await getServices(),
|
||||
services: services,
|
||||
defaultService: defaultService,
|
||||
defaultPort: defaultPort,
|
||||
devServerPort: devServerPort,
|
||||
|
@ -294,29 +294,6 @@ async function nginxGetBin() {
|
|||
}
|
||||
}
|
||||
|
||||
async function getServices() {
|
||||
let services;
|
||||
let startPort = defaultPort + 1;
|
||||
services = [];
|
||||
|
||||
const serviceDirs = await fs.readdir(servicesDir);
|
||||
const exclude = ['loopback'];
|
||||
|
||||
for (let service of serviceDirs) {
|
||||
let index = `${servicesDir}/${service}/server/server.js`;
|
||||
if (!await fs.exists(index) || exclude.indexOf(service) !== -1) continue;
|
||||
|
||||
let port = service == defaultService ? defaultPort : startPort++;
|
||||
services.push({
|
||||
name: service,
|
||||
index: index,
|
||||
port: port
|
||||
});
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
// Webpack
|
||||
|
||||
gulp.task('webpack', function(callback) {
|
||||
|
@ -562,9 +539,9 @@ function execP(command) {
|
|||
* @param {String} args The list of gulp task names
|
||||
* @return {Promise} The promise
|
||||
*/
|
||||
function runSequenceP() {
|
||||
function runSequenceP(...args) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let args = Array.prototype.slice.call(arguments);
|
||||
args = Array.prototype.slice.call(args);
|
||||
args.push(err => {
|
||||
if (err)
|
||||
reject(err);
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
FROM vn-loopback:latest
|
||||
|
||||
COPY agency /app
|
||||
WORKDIR /app
|
||||
CMD ["pm2-docker", "./server/server.js"]
|
|
@ -1,18 +0,0 @@
|
|||
{
|
||||
"name": "vn-agency",
|
||||
"version": "1.0.0",
|
||||
"main": "server/server.js",
|
||||
"scripts": {
|
||||
"start": "node .",
|
||||
"posttest": "npm run lint && nsp check"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.verdnatura.es/salix"
|
||||
},
|
||||
"license": "GPL-3.0",
|
||||
"description": "vn-agency",
|
||||
"dependencies": {
|
||||
"vn-loopback": "file:../loopback"
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
|
||||
var vnLoopback = require('vn-loopback/server/server.js');
|
||||
|
||||
var app = module.exports = vnLoopback.loopback();
|
||||
vnLoopback.boot(app, __dirname, module);
|
|
@ -1,7 +0,0 @@
|
|||
FROM vn-loopback:latest
|
||||
|
||||
COPY auth /app
|
||||
COPY nginx/static/webpack-assets.json /loopback/client/
|
||||
|
||||
WORKDIR /app
|
||||
CMD ["pm2-docker", "./server/server.js"]
|
|
@ -1,19 +0,0 @@
|
|||
{
|
||||
"name": "vn-auth",
|
||||
"version": "1.0.0",
|
||||
"main": "server/server.js",
|
||||
"scripts": {
|
||||
"start": "node .",
|
||||
"posttest": "npm run lint && nsp check"
|
||||
},
|
||||
"dependencies": {
|
||||
"md5": "^2.2.1",
|
||||
"vn-loopback": "file:../loopback"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.verdnatura.es/salix"
|
||||
},
|
||||
"license": "GPL-3.0",
|
||||
"description": "Authentication service"
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
|
||||
var vnLoopback = require('vn-loopback/server/server.js');
|
||||
|
||||
var app = module.exports = vnLoopback.loopback();
|
||||
app.set('applications', require('./application.json'));
|
||||
vnLoopback.boot(app, __dirname, module);
|
|
@ -1,5 +0,0 @@
|
|||
FROM vn-loopback:latest
|
||||
|
||||
COPY claim /app
|
||||
WORKDIR /app
|
||||
CMD ["pm2-docker", "./server/server.js"]
|
|
@ -1,18 +0,0 @@
|
|||
{
|
||||
"name": "vn-claim",
|
||||
"version": "1.0.0",
|
||||
"main": "server/server.js",
|
||||
"scripts": {
|
||||
"start": "node .",
|
||||
"posttest": "npm run lint && nsp check"
|
||||
},
|
||||
"dependencies": {
|
||||
"vn-loopback": "file:../loopback"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.verdnatura.es/salix"
|
||||
},
|
||||
"license": "GPL-3.0",
|
||||
"description": "vn-claim"
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
|
||||
var vnLoopback = require('vn-loopback/server/server.js');
|
||||
|
||||
var app = module.exports = vnLoopback.loopback();
|
||||
vnLoopback.boot(app, __dirname, module);
|
|
@ -1,6 +0,0 @@
|
|||
FROM vn-loopback:latest
|
||||
|
||||
COPY client /app
|
||||
WORKDIR /app
|
||||
CMD ["pm2-docker", "./server/server.js"]
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
{
|
||||
"name": "vn-client",
|
||||
"description": "Client service",
|
||||
"version": "1.0.0",
|
||||
"license": "GPL-3.0",
|
||||
"main": "server/server.js",
|
||||
"scripts": {
|
||||
"start": "node .",
|
||||
"posttest": "npm run lint && nsp check"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.verdnatura.es/salix"
|
||||
},
|
||||
"dependencies": {
|
||||
"request": "^2.83.0",
|
||||
"vn-loopback": "file:../loopback"
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
|
||||
var vnLoopback = require('vn-loopback/server/server.js');
|
||||
|
||||
var app = module.exports = vnLoopback.loopback();
|
||||
vnLoopback.boot(app, __dirname, module);
|
|
@ -1,6 +0,0 @@
|
|||
FROM vn-loopback:latest
|
||||
|
||||
COPY item /app
|
||||
WORKDIR /app
|
||||
CMD ["pm2-docker", "./server/server.js"]
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
"name": "vn-item",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"uuid": {
|
||||
"version": "3.2.1",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.2.1.tgz",
|
||||
"integrity": "sha512-jZnMwlb9Iku/O3smGWvZhauCf6cvvpKi4BKRiliS3cxnI+Gz9j5MEpTz2UFuXiKPJocb7gnsLHwiS05ige5BEA=="
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
{
|
||||
"name": "vn-item",
|
||||
"version": "1.0.0",
|
||||
"main": "server/server.js",
|
||||
"scripts": {
|
||||
"start": "node .",
|
||||
"posttest": "npm run lint && nsp check"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.verdnatura.es/salix"
|
||||
},
|
||||
"license": "GPL-3.0",
|
||||
"description": "vn-item",
|
||||
"dependencies": {
|
||||
"uuid": "^3.1.0",
|
||||
"vn-loopback": "file:../loopback"
|
||||
}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
var vnLoopback = require('vn-loopback/server/server.js');
|
||||
|
||||
var app = module.exports = vnLoopback.loopback();
|
||||
vnLoopback.boot(app, __dirname, module);
|
|
@ -1,4 +0,0 @@
|
|||
FROM node:8-slim
|
||||
|
||||
COPY . /loopback
|
||||
RUN npm -g install pm2
|
|
@ -6,8 +6,8 @@
|
|||
</head>
|
||||
<body ng-app="vnAuth">
|
||||
<vn-login></vn-login>
|
||||
<% for (let jsFile of assets('auth')) { %>
|
||||
<script type="text/javascript" src="<%= jsFile %>"></script>
|
||||
<% for (let jsFile of assets) { %>
|
||||
<script type="text/javascript" src="<%= jsFile %>"></script>
|
||||
<% } %>
|
||||
</body>
|
||||
</html>
|
|
@ -10,7 +10,7 @@
|
|||
<script type="text/javascript"
|
||||
src="/static/routes.js?<%= version %>">
|
||||
</script>
|
||||
<% for (let jsFile of assets('salix')) { %>
|
||||
<% for (let jsFile of assets) { %>
|
||||
<script type="text/javascript" src="<%= jsFile %>"></script>
|
||||
<% } %>
|
||||
</body>
|
|
@ -22,5 +22,7 @@
|
|||
"Cannot check Equalization Tax in this NIF/CIF": "Cannot check Equalization Tax in this NIF/CIF",
|
||||
"You can't create an order for a frozen client": "You can't create an order for a frozen client",
|
||||
"This address doesn't exist": "This address doesn't exist",
|
||||
"NO_AGENCY_AVAILABLE": "NO_AGENCY_AVAILABLE"
|
||||
"NO_AGENCY_AVAILABLE": "NO_AGENCY_AVAILABLE",
|
||||
"Warehouse cannot be blank": "Warehouse cannot be blank",
|
||||
"Agency cannot be blank": "Agency cannot be blank"
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,27 +1,30 @@
|
|||
{
|
||||
"name": "vn-loopback",
|
||||
"version": "1.0.0",
|
||||
"main": "server/server.js",
|
||||
"scripts": {
|
||||
"start": "node ."
|
||||
},
|
||||
"dependencies": {
|
||||
"compression": "^1.0.3",
|
||||
"cookie-parser": "^1.4.3",
|
||||
"cors": "^2.5.2",
|
||||
"fs-extra": "^5.0.0",
|
||||
"helmet": "^1.3.0",
|
||||
"i18n": "^0.8.3",
|
||||
"loopback": "^3.14.0",
|
||||
"loopback-boot": "^2.26.2",
|
||||
"loopback-component-explorer": "^4.2.0",
|
||||
"loopback-connector-mysql": "^3.0.0",
|
||||
"loopback-connector-remote": "^3.1.1",
|
||||
"loopback": "^3.24.0",
|
||||
"loopback-boot": "^2.27.1",
|
||||
"loopback-component-explorer": "^6.3.1",
|
||||
"loopback-connector-mysql": "^5.3.1",
|
||||
"loopback-connector-remote": "^3.4.0",
|
||||
"loopback-context": "^3.3.0",
|
||||
"md5": "^2.2.1",
|
||||
"object-diff": "0.0.4",
|
||||
"object.pick": "^1.3.0",
|
||||
"request": "^2.83.0",
|
||||
"require-yaml": "0.0.1",
|
||||
"serve-favicon": "^2.0.1",
|
||||
"strong-error-handler": "^2.1.0",
|
||||
"object-diff": "0.0.4",
|
||||
"object.pick": "^1.3.0"
|
||||
"uuid": "^3.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nsp": "^2.1.0"
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
var url = require('url');
|
||||
var md5 = require('md5');
|
||||
let url = require('url');
|
||||
let md5 = require('md5');
|
||||
|
||||
module.exports = function(app) {
|
||||
let User = app.models.User;
|
||||
let applications = app.get('applications');
|
||||
|
||||
app.get('/', function(req, res) {
|
||||
app.renderIndex(res);
|
||||
app.get('/auth/', function(req, res) {
|
||||
res.render('auth.ejs', {
|
||||
assets: app.getWpAssets('auth')
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/login', function(req, res) {
|
||||
app.post('/auth/login', function(req, res) {
|
||||
let body = req.body;
|
||||
let user = body.user;
|
||||
let password = body.password;
|
||||
|
@ -47,11 +49,11 @@ module.exports = function(app) {
|
|||
apiKey = query.apiKey;
|
||||
continueUrl = query.continue;
|
||||
} catch (e) {
|
||||
apiKey = 'default';
|
||||
continueUrl = null;
|
||||
}
|
||||
|
||||
let loginUrl = applications[apiKey];
|
||||
if (!apiKey) apiKey = 'default';
|
||||
let loginUrl = applications[apiKey] || '/login';
|
||||
|
||||
res.json({
|
||||
token: token.id,
|
||||
|
@ -84,7 +86,7 @@ module.exports = function(app) {
|
|||
}
|
||||
});
|
||||
|
||||
app.get('/logout', function(req, res) {
|
||||
app.get('/auth/logout', function(req, res) {
|
||||
User.logout(req.accessToken.id, () => {
|
||||
res.redirect('/');
|
||||
});
|
|
@ -1,13 +1,19 @@
|
|||
module.exports = function(app) {
|
||||
let models = app.models;
|
||||
let bootTimestamp = new Date().getTime();
|
||||
|
||||
app.get('/', function(req, res) {
|
||||
let token = req.cookies.vnToken;
|
||||
validateToken(token, function(isValid) {
|
||||
if (isValid)
|
||||
app.renderIndex(res);
|
||||
else
|
||||
if (!isValid) {
|
||||
redirectToAuth(res, req.get('origin'));
|
||||
return;
|
||||
}
|
||||
|
||||
res.render('index.ejs', {
|
||||
assets: app.getWpAssets('salix'),
|
||||
version: bootTimestamp
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -45,9 +51,9 @@ module.exports = function(app) {
|
|||
let token = req.headers.authorization;
|
||||
|
||||
validateToken(token, function(isValid) {
|
||||
if (isValid) {
|
||||
if (isValid)
|
||||
res.json(null);
|
||||
} else {
|
||||
else {
|
||||
res.status(401).json({
|
||||
message: 'Invalid token'
|
||||
});
|
||||
|
@ -82,7 +88,7 @@ module.exports = function(app) {
|
|||
};
|
||||
models.RoleMapping.find(query, function(_, roles) {
|
||||
if (roles) {
|
||||
var acl = {
|
||||
let acl = {
|
||||
userProfile: {},
|
||||
roles: {}
|
||||
};
|
||||
|
@ -99,9 +105,8 @@ module.exports = function(app) {
|
|||
acl.userProfile.username = userProfile.username;
|
||||
acl.userProfile.warehouseId = 1;
|
||||
sendACL(res, acl);
|
||||
} else {
|
||||
} else
|
||||
sendACL(res, {});
|
||||
}
|
||||
});
|
||||
} else
|
||||
sendACL(res, {});
|
||||
|
@ -129,12 +134,13 @@ module.exports = function(app) {
|
|||
|
||||
function encodeUri(object) {
|
||||
let uri = '';
|
||||
for (var key in object)
|
||||
for (let key in object) {
|
||||
if (object[key]) {
|
||||
if (uri.length > 0)
|
||||
uri += '&';
|
||||
uri += encodeURIComponent(key) + '=';
|
||||
uri += encodeURIComponent(object[key]);
|
||||
}
|
||||
}
|
||||
return uri;
|
||||
}
|
|
@ -1,14 +1,16 @@
|
|||
let loopback = require('loopback');
|
||||
let boot = require('loopback-boot');
|
||||
let DataSource = require('loopback-datasource-juggler').DataSource;
|
||||
let fs = require('fs-extra');
|
||||
let i18n = require('i18n');
|
||||
let path = require('path');
|
||||
require('require-yaml');
|
||||
const cookieParser = require('cookie-parser');
|
||||
const loopback = require('loopback');
|
||||
const boot = require('loopback-boot');
|
||||
const DataSource = require('loopback-datasource-juggler').DataSource;
|
||||
const fs = require('fs-extra');
|
||||
const i18n = require('i18n');
|
||||
const path = require('path');
|
||||
const loopbackConnector = require('loopback-connector');
|
||||
|
||||
let _resolveConnector = DataSource._resolveConnector;
|
||||
|
||||
DataSource._resolveConnector = function(name) {
|
||||
DataSource._resolveConnector = function(...args) {
|
||||
let name = args[0];
|
||||
let testPath = `${__dirname}/connectors/${name}.js`;
|
||||
|
||||
if (fs.existsSync(testPath)) {
|
||||
|
@ -18,132 +20,144 @@ DataSource._resolveConnector = function(name) {
|
|||
};
|
||||
}
|
||||
|
||||
return _resolveConnector.apply(this, arguments);
|
||||
return _resolveConnector.apply(this, args);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
loopback: loopback,
|
||||
loopbackConnector: loopbackConnector,
|
||||
boot: vnBoot
|
||||
};
|
||||
let app = loopback();
|
||||
let rootDir = __dirname;
|
||||
|
||||
function vnBoot(app, rootDir, rootModule) {
|
||||
// Internationalization
|
||||
module.exports = app;
|
||||
|
||||
let localeDir = `${__dirname}/../common/locale`;
|
||||
// TODO: It should be stored at some config file
|
||||
app.set('api key', 'salix');
|
||||
app.set('url auth', '/auth');
|
||||
app.set('applications', require('./application.json'));
|
||||
|
||||
if (fs.existsSync(localeDir)) {
|
||||
i18n.configure({
|
||||
directory: localeDir,
|
||||
defaultLocale: 'es'
|
||||
});
|
||||
app.use(cookieParser());
|
||||
|
||||
app.use(i18n.init);
|
||||
}
|
||||
// Internationalization
|
||||
|
||||
// View
|
||||
let localeDir = `${__dirname}/../common/locale`;
|
||||
|
||||
let wpAssets;
|
||||
let viewDir = `${rootDir}/../client`;
|
||||
|
||||
if (fs.existsSync(viewDir)) {
|
||||
app.set('view engine', 'ejs');
|
||||
app.set('views', viewDir);
|
||||
app.use(loopback.static(path.resolve(rootDir, '../client')));
|
||||
}
|
||||
|
||||
const buildVersion = new Date().getTime();
|
||||
|
||||
app.renderIndex = async res => {
|
||||
let assetsDirs = [viewDir, `${__dirname}/../../../dist`];
|
||||
|
||||
for (let assetsDir of assetsDirs) {
|
||||
let wpAssetsFile = `${assetsDir}/webpack-assets.json`;
|
||||
if (fs.existsSync(wpAssetsFile)) {
|
||||
wpAssets = require(wpAssetsFile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
res.render(`${viewDir}/index.ejs`, {
|
||||
assets: assets,
|
||||
version: buildVersion
|
||||
});
|
||||
|
||||
function assets(entryPoint) {
|
||||
let jsFiles = [];
|
||||
let regex = new RegExp(`(^|~)${entryPoint}($|~)`);
|
||||
|
||||
for (let asset in wpAssets) {
|
||||
if (regex.test(asset))
|
||||
jsFiles.push(wpAssets[asset].js);
|
||||
}
|
||||
|
||||
return jsFiles;
|
||||
}
|
||||
};
|
||||
|
||||
// Initialization
|
||||
|
||||
app.start = port => {
|
||||
function onListen() {
|
||||
app.emit('started');
|
||||
let packageJson = require(`${rootDir}/../package.json`);
|
||||
let appName = packageJson.name;
|
||||
let baseUrl = app.get('url').replace(/\/$/, '');
|
||||
console.log(`Web server ${appName} listening at: %s`, `${baseUrl}/explorer`);
|
||||
}
|
||||
|
||||
let args = port ? [port, onListen] : [onListen];
|
||||
return app.listen(...args);
|
||||
};
|
||||
|
||||
let config = require('./config.json');
|
||||
|
||||
for (let key in config)
|
||||
app.set(key, config[key]);
|
||||
|
||||
let modelConfigFiles = [
|
||||
`${__dirname}/model-config.json`,
|
||||
`${rootDir}/model-config.json`
|
||||
];
|
||||
|
||||
let modelConfig = {};
|
||||
|
||||
for (file of modelConfigFiles) {
|
||||
if (fs.existsSync(file))
|
||||
Object.assign(modelConfig, require(file));
|
||||
}
|
||||
|
||||
let bootOptions = {
|
||||
appRootDir: __dirname,
|
||||
appConfigRootDir: rootDir,
|
||||
modelsRootDir: rootDir,
|
||||
models: modelConfig,
|
||||
modelSources: [
|
||||
`loopback/common/models`,
|
||||
`loopback/server/models`,
|
||||
`${__dirname}/../common/models`,
|
||||
`${rootDir}/../common/models`
|
||||
],
|
||||
mixinDirs: [
|
||||
`loopback/common/mixins`,
|
||||
`loopback/server/mixins`,
|
||||
`${__dirname}/../common/mixins`,
|
||||
`${rootDir}/../common/mixins`
|
||||
],
|
||||
bootDirs: [
|
||||
`${__dirname}/boot`,
|
||||
`${rootDir}/boot`
|
||||
]
|
||||
};
|
||||
|
||||
if (fs.existsSync(`/config`))
|
||||
bootOptions.dsRootDir = `/config`;
|
||||
|
||||
boot(app, bootOptions, function(err) {
|
||||
if (err) throw err;
|
||||
if (require.main === rootModule)
|
||||
app.start();
|
||||
if (fs.existsSync(localeDir)) {
|
||||
i18n.configure({
|
||||
directory: localeDir,
|
||||
defaultLocale: 'es'
|
||||
});
|
||||
|
||||
app.use(i18n.init);
|
||||
}
|
||||
|
||||
// View
|
||||
|
||||
let viewDir = `${rootDir}/../client`;
|
||||
|
||||
if (fs.existsSync(viewDir)) {
|
||||
app.set('view engine', 'ejs');
|
||||
app.set('views', viewDir);
|
||||
app.use(loopback.static(path.resolve(rootDir, '../client')));
|
||||
}
|
||||
|
||||
let assetsPath = [
|
||||
viewDir,
|
||||
`${__dirname}/../../../dist`
|
||||
];
|
||||
|
||||
let wpAssets;
|
||||
let wpAssetsFound = false;
|
||||
|
||||
for (let assetsDir of assetsPath) {
|
||||
let wpAssetsFile = `${assetsDir}/webpack-assets.json`;
|
||||
wpAssetsFound = fs.existsSync(wpAssetsFile);
|
||||
if (wpAssetsFound) {
|
||||
wpAssets = require(wpAssetsFile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
app.getWpAssets = function(entryPoint) {
|
||||
if (!wpAssetsFound)
|
||||
throw new Error('webpack-assets.json file not found');
|
||||
|
||||
let jsFiles = [];
|
||||
let regex = new RegExp(`(^|~)${entryPoint}($|~)`);
|
||||
|
||||
for (let asset in wpAssets) {
|
||||
if (regex.test(asset))
|
||||
jsFiles.push(wpAssets[asset].js);
|
||||
}
|
||||
|
||||
return jsFiles;
|
||||
};
|
||||
|
||||
// Initialization
|
||||
|
||||
app.start = function(port, callback) {
|
||||
function onListen() {
|
||||
let baseUrl = app.get('url').replace(/\/$/, '');
|
||||
let explorerPath = app.get('loopback-component-explorer').mountPath;
|
||||
console.log(`Browse your REST API at: %s`, `${baseUrl}${explorerPath}`);
|
||||
app.emit('started');
|
||||
}
|
||||
|
||||
let args = port ? [port, onListen] : [onListen];
|
||||
return app.listen(...args);
|
||||
};
|
||||
|
||||
let config = require('./config.json');
|
||||
|
||||
for (let key in config)
|
||||
app.set(key, config[key]);
|
||||
|
||||
let servicesDir = `${__dirname}/../..`;
|
||||
|
||||
let modelConfigFiles = [
|
||||
`${__dirname}/model-config.json`
|
||||
];
|
||||
let modelSources = [
|
||||
`loopback/common/models`,
|
||||
`loopback/server/models`,
|
||||
`${__dirname}/../common/models`
|
||||
];
|
||||
let mixinDirs = [
|
||||
`loopback/common/mixins`,
|
||||
`loopback/server/mixins`,
|
||||
`${__dirname}/../common/mixins`
|
||||
];
|
||||
let bootDirs = [
|
||||
`${__dirname}/boot`
|
||||
];
|
||||
|
||||
let services = require(`${servicesDir}/services.yml`);
|
||||
for (let service of services) {
|
||||
let baseDir = `${servicesDir}/${service}`;
|
||||
modelConfigFiles.push(`${baseDir}/server/model-config.json`);
|
||||
modelSources.push(`${baseDir}/common/models`);
|
||||
mixinDirs.push(`${baseDir}/common/mixins`);
|
||||
bootDirs.push(`${baseDir}/server/boot`);
|
||||
}
|
||||
|
||||
let models = {};
|
||||
for (file of modelConfigFiles) {
|
||||
if (fs.existsSync(file))
|
||||
Object.assign(models, require(file));
|
||||
}
|
||||
|
||||
let bootOptions = {
|
||||
appRootDir: __dirname,
|
||||
appConfigRootDir: rootDir,
|
||||
modelsRootDir: rootDir,
|
||||
models: models,
|
||||
modelSources: modelSources,
|
||||
mixinDirs: mixinDirs,
|
||||
bootDirs: bootDirs
|
||||
};
|
||||
|
||||
if (fs.existsSync(`/etc/salix`))
|
||||
bootOptions.dsRootDir = `/etc/salix`;
|
||||
|
||||
boot(app, bootOptions, function(err) {
|
||||
if (err) throw err;
|
||||
if (require.main === module)
|
||||
app.start();
|
||||
});
|
||||
|
|
|
@ -26,8 +26,8 @@ http {
|
|||
autoindex off;
|
||||
|
||||
{{#services}}
|
||||
location ~ ^/{{name}}(?:/(.*))?$ {
|
||||
proxy_pass http://127.0.0.1:{{port}}/$1$is_args$args;
|
||||
location ~ ^/{{.}}(?:/(.*))?$ {
|
||||
proxy_pass http://127.0.0.1:{{defaultPort}}/$1$is_args$args;
|
||||
}
|
||||
{{/services}}
|
||||
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
FROM vn-loopback:latest
|
||||
|
||||
COPY order /app
|
||||
WORKDIR /app
|
||||
CMD ["pm2-docker", "./server/server.js"]
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
{
|
||||
"name": "vn-order",
|
||||
"version": "1.0.0",
|
||||
"main": "server/server.js",
|
||||
"scripts": {
|
||||
"start": "node .",
|
||||
"posttest": "npm run lint && nsp check"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.verdnatura.es/salix"
|
||||
},
|
||||
"license": "GPL-3.0",
|
||||
"description": "vn-order",
|
||||
"dependencies": {
|
||||
"uuid": "^3.1.0",
|
||||
"vn-loopback": "file:../loopback"
|
||||
}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
var vnLoopback = require('vn-loopback/server/server.js');
|
||||
|
||||
var app = module.exports = vnLoopback.loopback();
|
||||
vnLoopback.boot(app, __dirname, module);
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"name": "vn-module",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"md5": "^2.2.1",
|
||||
"vn-loopback": "file:./loopback"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.verdnatura.es/salix"
|
||||
},
|
||||
"license": "GPL-3.0",
|
||||
"description": "Loopback modules"
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
FROM vn-loopback:latest
|
||||
|
||||
COPY route /app
|
||||
WORKDIR /app
|
||||
CMD ["pm2-docker", "./server/server.js"]
|
|
@ -1,18 +0,0 @@
|
|||
{
|
||||
"name": "vn-route",
|
||||
"version": "1.0.0",
|
||||
"main": "server/server.js",
|
||||
"scripts": {
|
||||
"start": "node .",
|
||||
"posttest": "npm run lint && nsp check"
|
||||
},
|
||||
"dependencies": {
|
||||
"vn-loopback": "file:../loopback"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.verdnatura.es/salix"
|
||||
},
|
||||
"license": "GPL-3.0",
|
||||
"description": "Routes administration"
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
|
||||
var vnLoopback = require('vn-loopback/server/server.js');
|
||||
|
||||
var app = module.exports = vnLoopback.loopback();
|
||||
vnLoopback.boot(app, __dirname, module);
|
|
@ -1,6 +0,0 @@
|
|||
FROM vn-loopback:latest
|
||||
|
||||
COPY salix /app
|
||||
COPY nginx/static/webpack-assets.json /loopback/client/
|
||||
WORKDIR /app
|
||||
CMD ["pm2-docker", "./server/server.js"]
|
|
@ -1,19 +0,0 @@
|
|||
{
|
||||
"name": "salix",
|
||||
"version": "1.0.0",
|
||||
"main": "server/server.js",
|
||||
"scripts": {
|
||||
"start": "node .",
|
||||
"posttest": "npm run lint && nsp check"
|
||||
},
|
||||
"dependencies": {
|
||||
"cookie-parser": "^1.4.3",
|
||||
"vn-loopback": "file:../loopback"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.verdnatura.es/salix"
|
||||
},
|
||||
"license": "GPL-3.0",
|
||||
"description": "Salix application service"
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
|
||||
var cookieParser = require('cookie-parser');
|
||||
var vnLoopback = require('vn-loopback/server/server.js');
|
||||
|
||||
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, module);
|
|
@ -0,0 +1,12 @@
|
|||
[
|
||||
client,
|
||||
item,
|
||||
ticket,
|
||||
order,
|
||||
claim,
|
||||
route,
|
||||
agency,
|
||||
travel
|
||||
# mailer
|
||||
# print
|
||||
]
|
|
@ -1,5 +0,0 @@
|
|||
FROM vn-loopback:latest
|
||||
|
||||
COPY ticket /app
|
||||
WORKDIR /app
|
||||
CMD ["pm2-docker", "./server/server.js"]
|
|
@ -1,18 +0,0 @@
|
|||
{
|
||||
"name": "vn-ticket",
|
||||
"version": "1.0.0",
|
||||
"main": "server/server.js",
|
||||
"scripts": {
|
||||
"start": "node .",
|
||||
"posttest": "npm run lint && nsp check"
|
||||
},
|
||||
"dependencies": {
|
||||
"vn-loopback": "file:../loopback"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.verdnatura.es/salix"
|
||||
},
|
||||
"license": "GPL-3.0",
|
||||
"description": "vn-ticket"
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
|
||||
var vnLoopback = require('vn-loopback/server/server.js');
|
||||
|
||||
var app = module.exports = vnLoopback.loopback();
|
||||
vnLoopback.boot(app, __dirname, module);
|
|
@ -1,6 +0,0 @@
|
|||
FROM vn-loopback:latest
|
||||
|
||||
COPY travel /app
|
||||
WORKDIR /app
|
||||
CMD ["pm2-docker", "./server/server.js"]
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
{
|
||||
"name": "vn-travel",
|
||||
"version": "1.0.0",
|
||||
"main": "server/server.js",
|
||||
"scripts": {
|
||||
"start": "node .",
|
||||
"posttest": "npm run lint && nsp check"
|
||||
},
|
||||
"dependencies": {
|
||||
"vn-loopback": "file:../loopback"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.verdnatura.es/salix"
|
||||
},
|
||||
"license": "GPL-3.0",
|
||||
"description": "vn-travel"
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
var vnLoopback = require('vn-loopback/server/server.js');
|
||||
|
||||
var app = module.exports = vnLoopback.loopback();
|
||||
vnLoopback.boot(app, __dirname, module);
|
|
@ -5,8 +5,8 @@ const merge = require('webpack-merge');
|
|||
const AssetsWebpackPlugin = require('assets-webpack-plugin');
|
||||
const wpConfig = require('./webpack.config.yml');
|
||||
|
||||
let mode = process.env.NODE_ENV;
|
||||
mode = mode == 'production' ? mode : 'development';
|
||||
let env = process.env.NODE_ENV || 'development';
|
||||
let mode = env == 'development' ? env : 'production';
|
||||
|
||||
let outputPath = path.join(__dirname, wpConfig.buildDir);
|
||||
|
||||
|
@ -56,10 +56,10 @@ let baseConfig = {
|
|||
]
|
||||
},
|
||||
optimization: {
|
||||
runtimeChunk: true,
|
||||
splitChunks: {
|
||||
chunks: 'all',
|
||||
},
|
||||
runtimeChunk: true
|
||||
}
|
||||
},
|
||||
resolve: {
|
||||
modules: [
|
||||
|
@ -79,6 +79,7 @@ let baseConfig = {
|
|||
devtool: 'source-map',
|
||||
stats: {
|
||||
modules: false,
|
||||
assets: false,
|
||||
colors: true
|
||||
}
|
||||
};
|
||||
|
@ -103,7 +104,7 @@ let devConfig = {
|
|||
chunkFilename: '[id].js'
|
||||
},
|
||||
devServer: {
|
||||
host: '127.0.0.1',
|
||||
host: 'localhost',
|
||||
port: wpConfig.devServerPort,
|
||||
publicPath: '/',
|
||||
contentBase: wpConfig.buildDir,
|
||||
|
@ -114,5 +115,5 @@ let devConfig = {
|
|||
}
|
||||
};
|
||||
|
||||
let mrgConfig = mode === 'production' ? prodConfig : devConfig;
|
||||
let mrgConfig = mode === 'development' ? devConfig : prodConfig;
|
||||
module.exports = merge(baseConfig, mrgConfig);
|
||||
|
|
Loading…
Reference in New Issue