Skip to content

Commit b098f25

Browse files
added debug env var on dev mode and some additional logging and better seeding
1 parent 0aeea79 commit b098f25

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
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 nodemon server/'",
43-
"dev:noseed": "concurrently 'mongod --dbpath data' 'wait-on tcp:27017 && NODE_ENV=development nodemon server/'",
44-
"dev:win": "npm run clear && concurrently \"mongod --dbpath data\" \"wait-on tcp:27017&&SET 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/'",
43+
"dev:noseed": "concurrently 'mongod --dbpath data' 'wait-on tcp:27017 && NODE_ENV=development DEBUG=feathers nodemon server/'",
44+
"dev:win": "npm run clear && concurrently \"mongod --dbpath data\" \"wait-on tcp:27017&&SET NODE_ENV=development&&SET DEBUG=feathers&& nodemon --inspect server/\"",
4545
"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'",
4646
"coverage": "npm run clear && $npm_package_config_concurrently '$npm_package_config_mongoDev &>/dev/null' 'wait-on tcp:27017 && NODE_ENV=test istanbul cover $npm_package_config_mochaCoverage'"
4747
},
@@ -99,6 +99,7 @@
9999
"shortid": "~2.2.8",
100100
"slug": "~0.9.1",
101101
"trunc-html": "^1.1.2",
102+
"valid-url": "^1.0.9",
102103
"winston": "~3.0.0-rc1"
103104
},
104105
"devDependencies": {

server/hooks/save-remote-images.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
// For more information on hooks see: http://docs.feathersjs.com/api/hooks.html
33

44
const errors = require('feathers-errors');
5+
const { isEmpty } = require('lodash');
56
const fs = require('fs');
67
const path = require('path');
78
const request = require('request');
89
const faker = require('faker');
910
const mime = require('mime/lite');
11+
// const validUrl = require('valid-url');
1012

1113
module.exports = function (options = []) { // eslint-disable-line no-unused-vars
1214
return function async (hook) {
@@ -28,10 +30,19 @@ module.exports = function (options = []) { // eslint-disable-line no-unused-vars
2830

2931
// save all given fields and update the hook data
3032
options.forEach((field) => {
31-
if (!hook.data[field] || (typeof hook.data[field] === 'string' && hook.data[field].search(uploadsUrl) >= 0)) {
33+
if (isEmpty(hook.data[field]) || (typeof hook.data[field] === 'string' && hook.data[field].search(uploadsUrl) >= 0)) {
3234
// skip invalid and local data
35+
// hook.app.debug(`skip invalid and local data: ${field} - ${hook.data[field]}`);
3336
return;
3437
}
38+
// cant only check for validUrl as we also get blobs
39+
// if (!validUrl.isWebUri(hook.data[field])) {
40+
// // cancel on invalid image url
41+
// hook.app.debug(`cancel on invalid image url: ${hook.data[field]}`);
42+
// return;
43+
// }
44+
hook.app.debug(`try to get image: ${hook.data[field]}`);
45+
3546
loading++;
3647
imgCount++;
3748
// TODO: fix that to use the data _id or somethink similar
@@ -95,7 +106,7 @@ module.exports = function (options = []) { // eslint-disable-line no-unused-vars
95106
});
96107
}
97108

98-
hook.app.debug('Downloading', hook.data[field]);
109+
hook.app.debug(`Downloading: ${hook.data[field]}`);
99110
});
100111

101112
if (imgCount > 0 && loading <= 0) {
@@ -104,7 +115,7 @@ module.exports = function (options = []) { // eslint-disable-line no-unused-vars
104115
} else if (!imgCount) {
105116
resolve(hook);
106117
}
107-
} catch(err) {
118+
} catch (err) {
108119
// reject(err);
109120
if (imgCount) {
110121
hook.app.error('Thumbnail download failed');

server/seeder/development/users.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const seedHelpers = require('../../helper/seed-helpers');
2+
const faker = require('faker');
23

34
// eslint-disable-next-line no-unused-vars
45
module.exports = (seederstore) => {
@@ -13,7 +14,7 @@ module.exports = (seederstore) => {
1314
slug: '{{lorem.slug}}',
1415
isnothere: true,
1516
timezone: 'Europe/Berlin',
16-
avatar: '{{internet.avatar}}',
17+
avatar: () => seedHelpers.randomItem([faker.internet.avatar(), null]),
1718
isVerified : true,
1819
role : 'user',
1920
badgeIds: () => seedHelpers.randomItems(seederstore.badges, '_id', 0, seederstore.badges.length),
@@ -24,4 +25,4 @@ module.exports = (seederstore) => {
2425
}
2526
}]
2627
};
27-
};
28+
};

server/seeder/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ let configs = [...baseConfigs, ...developmentConfigs];
2121
// seed service and add results to the seeder store
2222
const seedAndAssign = async (config, seeder, app) => {
2323
const key = config.path;
24+
app.debug(`>> SEEDING: ${key}`);
2425
try {
2526
const res = await seeder.seed(config);
2627
if (_.isEmpty(seederstore[key])) {

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5564,6 +5564,10 @@ valid-data-url@^0.1.4:
55645564
version "0.1.4"
55655565
resolved "https://registry.yarnpkg.com/valid-data-url/-/valid-data-url-0.1.4.tgz#9480d7eb8d4f5675a8ad774e51068be7b0aef410"
55665566

5567+
valid-url@^1.0.9:
5568+
version "1.0.9"
5569+
resolved "https://registry.yarnpkg.com/valid-url/-/valid-url-1.0.9.tgz#1c14479b40f1397a75782f115e4086447433a200"
5570+
55675571
validate-npm-package-license@^3.0.1:
55685572
version "3.0.1"
55695573
resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.1.tgz#2804babe712ad3379459acfbe24746ab2c303fbc"

0 commit comments

Comments
 (0)