Merge branch 'dev' of https://git.verdnatura.es/salix into dev

This commit is contained in:
Dani Herrero 2017-06-07 13:28:03 +02:00
commit 544c69ecd8
16 changed files with 441 additions and 6 deletions

5
Jenkinsfile vendored
View File

@ -7,14 +7,15 @@ def branchName = "${env.BRANCH_NAME}";
def branchNameTest = "preprod";
def branchNameProd = "master";
def prefixDocker = "test";
def dockerNginxName = ["nginx", "-p 80:80 --privileged --link test-auth:auth --link test-salix:salix --link test-client:client"]
def dockerNginxName = ["nginx", "-p 80:80 --privileged --link test-auth:auth --link test-salix:salix --link test-client:client --link test-mailer:mailer"]
def dockerAuthName = ["auth", "-p 3000:3000"]
def dockerSalixName = ["salix", "-p 3001:3001"]
def dockerClientName = ["client", "-p 3002:3002"]
def dockerMailerName = ["mailer", "-p 3003:3003"]
def buildNumber = "${env.BUILD_NUMBER}";
def dockers = [dockerAuthName, dockerSalixName, dockerClientName, dockerNginxName]
def dockers = [dockerAuthName, dockerSalixName, dockerClientName, dockerMailerName, dockerNginxName]
node {

View File

@ -9,6 +9,8 @@ var fs = require('fs');
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var services = require("./gulpfiles/services.json");
// Configuration
var srcDir = './client';
@ -32,11 +34,27 @@ gulp.task('client', ['clean'], function() {
return gulp.start('watch', 'routes', 'locales', 'webpack-dev-server');
});
gulp.task('services', function() {
gulp.task('copy', function() {
var streams = [];
for (i=0; i < services.services.length; i++) {
var service = services.services[i];
for (j=0; j < services.files.length; j++) {
var file = services.files[j];
streams.push(gulp.src("./services/service/models/" + file)
.pipe(gulp.dest(service + "/common/models/")));
}
}
return merge(streams);
});
gulp.task('services', ['copy'], function() {
require('./services/auth/server/server.js').start();
require('./services/client/server/server.js').start();
require('./services/salix/server/server.js').start();
require('./services/mailer/server.js').start();
for (i=0; i < services.services.length; i++) {
require(services.services[i] + "/server/server.js").start();
}
});
gulp.task('clean', function() {

14
gulpfiles/services.json Normal file
View File

@ -0,0 +1,14 @@
{
"services": [
"./services/client",
"./services/production"
],
"files":[
"account.json",
"my-model.js",
"my-model.json",
"user.json"
]
}

View File

@ -0,0 +1,11 @@
FROM node:6.9.1
COPY . /app
WORKDIR /app
RUN npm install
CMD ["npm", "start"]
EXPOSE 3003

View File

@ -37,6 +37,10 @@ http {
location ~ ^/mailer(?:/(.*))?$ {
proxy_pass http://127.0.0.1:3003/$1$is_args$args;
}
location ~ ^/production(?:/(.*))?$ {
proxy_pass http://127.0.0.1:3004/$1$is_args$args;
}
# Este tiene que ser el último
location ~ ^(?:/(.*))?$ {
proxy_pass http://127.0.0.1:3001/$1$is_args$args;
}

View File

@ -19,7 +19,7 @@ http {
root /usr/share/nginx/html;
location /static {
location ~ ^/static(?:/(.*))?$ {
alias /usr/share/nginx/html;
autoindex on;
}
@ -32,6 +32,10 @@ http {
location ~ ^/mailer(?:/(.*))?$ {
proxy_pass http://mailer:3003/$1$is_args$args;
}
location ~ ^/production(?:/(.*))?$ {
proxy_pass http://production:3004/$1$is_args$args;
}
# Este tiene que ser el último
location ~ ^(?:/(.*))?$ {
proxy_pass http://salix:3001/$1$is_args$args;
}

View File

@ -0,0 +1,11 @@
FROM node:6.9.1
COPY . /app
WORKDIR /app
RUN npm install
CMD ["npm", "start"]
EXPOSE 3004

View File

@ -0,0 +1,46 @@
{
"name": "Account",
"base": "PersistedModel",
"validateUpsert": true,
"properties": {
"id": {
"type": "number",
"required": true
},
"name": {
"type": "string",
"required": true
},
"password": {
"type": "string",
"required": true
},
"active": {
"type": "boolean"
},
"email": {
"type": "string",
"required": true
},
"created": {
"type": "date"
},
"updated": {
"type": "date"
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "root",
"permission": "ALLOW"
}
]
}

View File

@ -0,0 +1,125 @@
module.exports = function(self) {
self.setup = function() {
self.super_.setup.call(this);
let disableMethods = {
'create': true,
'replaceOrCreate': true,
'patchOrCreate': true,
'upsert': true,
'updateOrCreate': true,
'exists': true,
'find': true,
'findOne': true,
'findById': true,
'deleteById': true,
'replaceById': true,
'updateAttributes': false,
'createChangeStream': true,
'updateAll': true,
'upsertWithWhere': true,
'count': true
};
for(let method in disableMethods) {
//this.disableRemoteMethod(method, disableMethods[method]);
}
}
self.installMethod = function(methodName, filterCb) {
this.remoteMethod(methodName, {
description: 'List items using a filter',
accessType: 'READ',
accepts: [
{
arg: 'filter',
type: 'object',
required: true,
description: 'Filter defining where',
http: function(ctx) {
return ctx.req.query;
}
}
],
returns: {
arg: 'data',
type: [this.modelName],
root: true
},
http: {
verb: 'get',
path: `/${methodName}`
}
});
this[methodName] = (params, cb) => {
let filter = removeEmpty(filterCb(params));
var response = {}
function returnValues(){
if(response.instances !== undefined && response.count !== undefined)
cb(null, response);
}
function error(){
cb(null, response);
}
this.find(filter, function(err, instances) {
if(!err){
response.instances = instances;
returnValues();
}
else{
error();
}
})
this.count(filter.where, function(err, totalCount){
if(!err){
response.count = totalCount;
returnValues();
}
else{
error();
}
})
};
};
}
function removeEmpty(o) {
if(Array.isArray(o)) {
let array = [];
for(let item of o) {
let i = removeEmpty(item);
if(!isEmpty(item))
array.push(item);
};
if(array.length > 0)
return array;
}
else if (typeof o === 'object') {
let object = {};
for(let key in o) {
let i = removeEmpty(o[key]);
if(!isEmpty(i))
object[key] = i;
}
if(Object.keys(object).length > 0)
return object;
}
else if (!isEmpty(o))
return o;
return undefined;
}
function isEmpty(value) {
return value === undefined || value === "";
}

View File

@ -0,0 +1,4 @@
{
"name": "MyModel",
"base": "PersistedModel"
}

View File

@ -0,0 +1,11 @@
{
"name": "user",
"base": "User",
"properties": {
"id": {
"id": true,
"type": "Number",
"forceId": false
}
}
}

View File

@ -1,7 +1,7 @@
{
"restApiRoot": "/api",
"host": "0.0.0.0",
"port": 3000,
"port": 3004,
"remoting": {
"context": false,
"rest": {

View File

@ -0,0 +1,46 @@
{
"name": "Account",
"base": "PersistedModel",
"validateUpsert": true,
"properties": {
"id": {
"type": "number",
"required": true
},
"name": {
"type": "string",
"required": true
},
"password": {
"type": "string",
"required": true
},
"active": {
"type": "boolean"
},
"email": {
"type": "string",
"required": true
},
"created": {
"type": "date"
},
"updated": {
"type": "date"
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "root",
"permission": "ALLOW"
}
]
}

View File

@ -0,0 +1,125 @@
module.exports = function(self) {
self.setup = function() {
self.super_.setup.call(this);
let disableMethods = {
'create': true,
'replaceOrCreate': true,
'patchOrCreate': true,
'upsert': true,
'updateOrCreate': true,
'exists': true,
'find': true,
'findOne': true,
'findById': true,
'deleteById': true,
'replaceById': true,
'updateAttributes': false,
'createChangeStream': true,
'updateAll': true,
'upsertWithWhere': true,
'count': true
};
for(let method in disableMethods) {
//this.disableRemoteMethod(method, disableMethods[method]);
}
}
self.installMethod = function(methodName, filterCb) {
this.remoteMethod(methodName, {
description: 'List items using a filter',
accessType: 'READ',
accepts: [
{
arg: 'filter',
type: 'object',
required: true,
description: 'Filter defining where',
http: function(ctx) {
return ctx.req.query;
}
}
],
returns: {
arg: 'data',
type: [this.modelName],
root: true
},
http: {
verb: 'get',
path: `/${methodName}`
}
});
this[methodName] = (params, cb) => {
let filter = removeEmpty(filterCb(params));
var response = {}
function returnValues(){
if(response.instances !== undefined && response.count !== undefined)
cb(null, response);
}
function error(){
cb(null, response);
}
this.find(filter, function(err, instances) {
if(!err){
response.instances = instances;
returnValues();
}
else{
error();
}
})
this.count(filter.where, function(err, totalCount){
if(!err){
response.count = totalCount;
returnValues();
}
else{
error();
}
})
};
};
}
function removeEmpty(o) {
if(Array.isArray(o)) {
let array = [];
for(let item of o) {
let i = removeEmpty(item);
if(!isEmpty(item))
array.push(item);
};
if(array.length > 0)
return array;
}
else if (typeof o === 'object') {
let object = {};
for(let key in o) {
let i = removeEmpty(o[key]);
if(!isEmpty(i))
object[key] = i;
}
if(Object.keys(object).length > 0)
return object;
}
else if (!isEmpty(o))
return o;
return undefined;
}
function isEmpty(value) {
return value === undefined || value === "";
}

View File

@ -0,0 +1,4 @@
{
"name": "MyModel",
"base": "PersistedModel"
}

View File

@ -0,0 +1,11 @@
{
"name": "user",
"base": "User",
"properties": {
"id": {
"id": true,
"type": "Number",
"forceId": false
}
}
}