Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Commit 28afc61

Browse files
Merge pull request #69 from Human-Connection/develop
update master
2 parents 3a2b9e6 + 8ed0e76 commit 28afc61

36 files changed

+568
-323
lines changed

config/default.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
"frontURL": "http://localhost:3000",
66
"public": "../public/",
77
"debug": true,
8+
"logLevel": "log",
89
"paginate": {
910
"default": 10,
10-
"max": 50
11+
"max": 100
1112
},
1213
"thumbor": {
1314
"url": "",

config/production.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"frontURL": "WEBAPP_BASE_URL",
66
"mongodb": "MONGO_DB",
77
"debug": true,
8+
"logLevel": "warn",
89
"smtpConfig": {
910
"host": "SMTP_HOST",
1011
"port": 587,

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"start": "concurrently 'mongod' 'wait-on tcp:27017 && NODE_ENV=production node server/'",
4040
"start:win": "concurrently \"mongod\" \"wait-on tcp:27017 &&SET NODE_ENV=production&& node server/\"",
4141
"dev:debug": "npm run clear && concurrently '$npm_package_config_mongoDev' 'wait-on tcp:27017 && NODE_ENV=development nodemon --inspect server/'",
42-
"dev": "npm run clear && concurrently '$npm_package_config_mongoDev' 'wait-on tcp:27017 && NODE_ENV=development DEBUG=feathers nodemon server/'",
42+
"dev": "npm run clear && concurrently '$npm_package_config_mongoDev' 'wait-on tcp:27017 && NODE_ENV=development nodemon server/'",
43+
"dev:local": "sh scripts/run-local.sh",
4344
"dev:noseed": "concurrently 'mongod --dbpath data' 'wait-on tcp:27017 && NODE_ENV=development DEBUG=feathers nodemon server/'",
4445
"dev:win": "npm run clear && concurrently \"mongod --dbpath /data/db\" \"wait-on tcp:27017&&cross-env NODE_ENV=development&&cross-env DEBUG=feathers&& nodemon --inspect server/\"",
4546
"mocha": "npm run clear && $npm_package_config_concurrently '$npm_package_config_mongoDev &>/dev/null' 'wait-on tcp:27017 && NODE_ENV=test $npm_package_config_mocha'",
@@ -111,7 +112,6 @@
111112
"istanbul": "1.1.0-alpha.1",
112113
"mocha": "~5.2.0",
113114
"nodemon": "~1.17.4",
114-
"shx": "^0.2.2",
115115
"wait-on": "~2.1.0"
116116
}
117117
}

scripts/run-local.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
# start app on the local network
4+
LOCAL_IP=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1');
5+
env API_HOST=$LOCAL_IP env WEBAPP_BASE_URL=http://$LOCAL_IP:3000 env API_BASE_URL=http://$LOCAL_IP:3030 env THUMBOR_URL=http://$LOCAL_IP:8888 yarn dev

server/helper/seed-helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ module.exports = {
100100
city: faker.address.city(),
101101
zipCode: faker.address.zipCode(),
102102
street: faker.address.streetAddress(),
103-
country: faker.address.country(),
103+
country: faker.address.countryCode(),
104104
lat: 54.032726 - (Math.random() * 10),
105105
lng: 6.558838 + (Math.random() * 10)
106106
});

server/hooks/create-excerpt.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,53 @@
44

55
const sanitizeHtml = require('sanitize-html');
66
const trunc = require('trunc-html');
7+
const { getByDot, setByDot } = require('feathers-hooks-common');
8+
const { isEmpty } = require('lodash');
79

810
const sanitizeOptions = {
9-
allowedTags: [ 'br' ]
11+
allowedTags: ['p', 'br', 'a', 'span', 'blockquote'],
12+
allowedAttributes: {
13+
a: ['href', 'class', 'target', 'data-*' , 'contenteditable'],
14+
span: ['contenteditable', 'class', 'data-*']
15+
},
1016
};
1117

1218
module.exports = function (options = {}) { // eslint-disable-line no-unused-vars
1319
return function (hook) {
1420

1521
options = Object.assign({ length: 120, field: 'content' }, options);
1622

17-
if(!hook.data || !hook.data[options.field]) {
23+
let content = getByDot(hook.data, options.field);
24+
25+
if(!hook.data || isEmpty(content)) {
1826
return hook;
1927
}
2028

2129
try {
2230
/* eslint no-use-before-define: 0 */ // --> OFF
23-
const content = sanitizeHtml(hook.data[options.field], sanitizeOptions)
31+
let contentSanitized = sanitizeHtml(content, sanitizeOptions)
2432
.replace(/\<br\s*\>|\<br\s*\/\>/ig, "\n")
2533
.replace(/(\ ){2,}/ig, ' ')
2634
.trim();
27-
hook.data[`${options.field}Excerpt`] = trunc(content, options.length, {
28-
ignoreTags: ['img', 'script', 'iframe']
29-
}).html;
35+
36+
contentBefore = trunc(content, 9999999999);
37+
const contentTruncated = trunc(contentSanitized, options.length);
38+
hook.app.debug('contentBefore');
39+
hook.app.debug(contentBefore.text.length);
40+
hook.app.debug('contentTruncated');
41+
hook.app.debug(contentTruncated.text.length);
42+
43+
const hasMore = contentBefore.text.length > (contentTruncated.text.length + 20);
44+
setByDot(hook.data, 'hasMore', hasMore);
45+
46+
// set excerpt
47+
setByDot(hook.data, `${options.field}Excerpt`, hasMore ? contentTruncated.html : content.replace(/(\ ){2,}/ig, ' '))
3048
} catch (err) {
31-
throw new Error('Text content needed!');
49+
throw new Error(err);
3250
}
33-
hook.data[options.field] = hook.data[options.field]
34-
.replace(/(\ ){2,}/ig, ' ')
51+
// trim content
52+
setByDot(hook.data, options.field, content.replace(/(\ ){2,}/ig, ' '));
3553

36-
return Promise.resolve(hook);
54+
return hook;
3755
};
3856
};

server/hooks/create-slug.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ const slug = require('slug');
33
const getUniqueSlug = require('../helper/get-unique-slug');
44
const { isEmpty } = require('lodash');
55

6-
module.exports = function (options = { field: null, overwrite: false, unique: true }) {
6+
module.exports = function (options = {}) {
77
return function (hook) {
8+
options = Object.assign({ field: null, overwrite: false, unique: true }, options);
9+
810
if (!options.field || !hook.data[options.field]) return hook;
911

1012
// do not overwrite existing slug

server/hooks/map-create-to-upsert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = function (upsertQuery) {
1515
}
1616

1717
params.mongoose = Object.assign({}, params.mongoose, { upsert: true });
18-
params.query = upsertQuery(context); // { address: '123' }
18+
params.query = upsertQuery(context);
1919

2020
return service.patch(null, data, params)
2121
.then(result => {

server/logger.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ const { createLogger, format, transports } = require('winston');
22
const env = process.env.NODE_ENV;
33

44
const logger = createLogger({
5-
level: 'warn',
5+
level: env !== 'production' ? 'warn' : 'debug',
66
format: format.json(),
77
transports: [
88
new transports.File({ filename: './data/error.log', level: 'error' }),
9+
new transports.File({ filename: './data/debug.log', level: 'debug' }),
910
new transports.File({ filename: './data/combined.log' })
1011
]
1112
});
@@ -22,6 +23,6 @@ logger.add(new transports.Console({
2223
return `${levelColors[info.level]}${date.toLocaleTimeString()} | ${info.level}: ${JSON.stringify(info.message)}\u001b[39m`;
2324
})
2425
),
25-
level: env === 'development' || 'test' ? 'debug' : 'warn'
26+
level: env === 'development' ? 'debug' : 'warn'
2627
}));
2728
module.exports = logger;

0 commit comments

Comments
 (0)