diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..471dd914b --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/client/auth/src/login/login.js b/client/auth/src/login/login.js index 47ab77baf..b92dd9ffa 100644 --- a/client/auth/src/login/login.js +++ b/client/auth/src/login/login.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) { diff --git a/client/salix/src/components/main-menu/main-menu.js b/client/salix/src/components/main-menu/main-menu.js index 0912d394e..62926a64d 100644 --- a/client/salix/src/components/main-menu/main-menu.js +++ b/client/salix/src/components/main-menu/main-menu.js @@ -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) { diff --git a/client/salix/src/components/main-menu/main-menu.spec.js b/client/salix/src/components/main-menu/main-menu.spec.js index 082e587cb..475495b2a 100644 --- a/client/salix/src/components/main-menu/main-menu.spec.js +++ b/client/salix/src/components/main-menu/main-menu.spec.js @@ -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(); diff --git a/gulpfile.js b/gulpfile.js index 77809c98a..0d8473ae7 100644 --- a/gulpfile.js +++ b/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); diff --git a/services/agency/Dockerfile b/services/agency/Dockerfile deleted file mode 100644 index 611cb8fbb..000000000 --- a/services/agency/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM vn-loopback:latest - -COPY agency /app -WORKDIR /app -CMD ["pm2-docker", "./server/server.js"] diff --git a/services/agency/package.json b/services/agency/package.json deleted file mode 100644 index 8c54fbaba..000000000 --- a/services/agency/package.json +++ /dev/null @@ -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" - } -} diff --git a/services/agency/server/server.js b/services/agency/server/server.js deleted file mode 100644 index b4a607c71..000000000 --- a/services/agency/server/server.js +++ /dev/null @@ -1,5 +0,0 @@ - -var vnLoopback = require('vn-loopback/server/server.js'); - -var app = module.exports = vnLoopback.loopback(); -vnLoopback.boot(app, __dirname, module); diff --git a/services/auth/Dockerfile b/services/auth/Dockerfile deleted file mode 100644 index 9d452364e..000000000 --- a/services/auth/Dockerfile +++ /dev/null @@ -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"] diff --git a/services/auth/package.json b/services/auth/package.json deleted file mode 100644 index 8800ae6c9..000000000 --- a/services/auth/package.json +++ /dev/null @@ -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" -} diff --git a/services/auth/server/server.js b/services/auth/server/server.js deleted file mode 100644 index 9df1876a0..000000000 --- a/services/auth/server/server.js +++ /dev/null @@ -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); diff --git a/services/claim/Dockerfile b/services/claim/Dockerfile deleted file mode 100644 index 70f5737ae..000000000 --- a/services/claim/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM vn-loopback:latest - -COPY claim /app -WORKDIR /app -CMD ["pm2-docker", "./server/server.js"] diff --git a/services/claim/package.json b/services/claim/package.json deleted file mode 100644 index ede1c3ced..000000000 --- a/services/claim/package.json +++ /dev/null @@ -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" -} diff --git a/services/claim/server/server.js b/services/claim/server/server.js deleted file mode 100644 index b4a607c71..000000000 --- a/services/claim/server/server.js +++ /dev/null @@ -1,5 +0,0 @@ - -var vnLoopback = require('vn-loopback/server/server.js'); - -var app = module.exports = vnLoopback.loopback(); -vnLoopback.boot(app, __dirname, module); diff --git a/services/client/Dockerfile b/services/client/Dockerfile deleted file mode 100644 index d943bab55..000000000 --- a/services/client/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM vn-loopback:latest - -COPY client /app -WORKDIR /app -CMD ["pm2-docker", "./server/server.js"] - diff --git a/services/client/package.json b/services/client/package.json deleted file mode 100644 index 39da50b71..000000000 --- a/services/client/package.json +++ /dev/null @@ -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" - } -} diff --git a/services/client/server/server.js b/services/client/server/server.js deleted file mode 100644 index b4a607c71..000000000 --- a/services/client/server/server.js +++ /dev/null @@ -1,5 +0,0 @@ - -var vnLoopback = require('vn-loopback/server/server.js'); - -var app = module.exports = vnLoopback.loopback(); -vnLoopback.boot(app, __dirname, module); diff --git a/services/item/Dockerfile b/services/item/Dockerfile deleted file mode 100644 index c8f40351b..000000000 --- a/services/item/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM vn-loopback:latest - -COPY item /app -WORKDIR /app -CMD ["pm2-docker", "./server/server.js"] - diff --git a/services/item/package-lock.json b/services/item/package-lock.json deleted file mode 100644 index fe3b78790..000000000 --- a/services/item/package-lock.json +++ /dev/null @@ -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==" - } - } -} diff --git a/services/item/package.json b/services/item/package.json deleted file mode 100644 index d77eb722b..000000000 --- a/services/item/package.json +++ /dev/null @@ -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" - } -} diff --git a/services/item/server/server.js b/services/item/server/server.js deleted file mode 100644 index 05280d0ce..000000000 --- a/services/item/server/server.js +++ /dev/null @@ -1,4 +0,0 @@ -var vnLoopback = require('vn-loopback/server/server.js'); - -var app = module.exports = vnLoopback.loopback(); -vnLoopback.boot(app, __dirname, module); diff --git a/services/loopback/Dockerfile b/services/loopback/Dockerfile deleted file mode 100644 index 65717223d..000000000 --- a/services/loopback/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM node:8-slim - -COPY . /loopback -RUN npm -g install pm2 diff --git a/services/auth/client/index.ejs b/services/loopback/client/auth.ejs similarity index 60% rename from services/auth/client/index.ejs rename to services/loopback/client/auth.ejs index 2ab44c6e6..1fd6988ad 100644 --- a/services/auth/client/index.ejs +++ b/services/loopback/client/auth.ejs @@ -6,8 +6,8 @@