From 6cc2d39d896071eafb375a45257ba8022435cf5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Sat, 11 Aug 2018 13:06:09 +0200 Subject: [PATCH 01/20] Typo in email --- config/cucumber.json | 2 +- config/local.example.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/cucumber.json b/config/cucumber.json index d9505d5..2453074 100644 --- a/config/cucumber.json +++ b/config/cucumber.json @@ -16,5 +16,5 @@ "runOnInit": false, "dropDatabase": false }, - "defaultEmail": "no-replay@human-connection.org" + "defaultEmail": "no-reply@human-connection.org" } diff --git a/config/local.example.json b/config/local.example.json index 8884088..d18203b 100644 --- a/config/local.example.json +++ b/config/local.example.json @@ -16,5 +16,5 @@ "runOnInit": true, "dropDatabase": false }, - "defaultEmail": "no-replay@human-connection.org" + "defaultEmail": "no-reply@human-connection.org" } From 24eec29393bae1fc4bb35e82963ac7e4abc8bb79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Sat, 11 Aug 2018 14:00:32 +0200 Subject: [PATCH 02/20] Sane configurations - no magic DON'T automagically create local.json Remove redundancy in config/ --- config/cucumber.json | 21 +++------------------ config/default.json | 9 +++++++-- config/local.example.json | 16 +--------------- config/test.json | 9 --------- server/index.js | 6 ------ 5 files changed, 11 insertions(+), 50 deletions(-) diff --git a/config/cucumber.json b/config/cucumber.json index 2453074..5825f80 100644 --- a/config/cucumber.json +++ b/config/cucumber.json @@ -1,20 +1,5 @@ { - "host": "localhost", - "port": 3030, - "baseURL": "http://localhost:3030", - "frontURL": "http://localhost:3000", - "smtpConfig": { - "host": "0.0.0.0", - "port": 1025, - "ignoreTLS": true - }, - "thumbor": { - "url": "", - "key": "" - }, - "seeder": { - "runOnInit": false, - "dropDatabase": false - }, - "defaultEmail": "no-reply@human-connection.org" + "port": 3031, + "baseURL": "http://localhost:3031", + "mongodb": "mongodb://localhost:27017/hc_api_test" } diff --git a/config/default.json b/config/default.json index 7f3b4e6..60810d2 100644 --- a/config/default.json +++ b/config/default.json @@ -17,8 +17,13 @@ "apiSecret": "TE9TqAk2xK[9EFJL", "sentry": {}, "seeder": { - "runOnInit": true, - "dropDatabase": true + "runOnInit": false, + "dropDatabase": false + }, + "smtpConfig": { + "host": "0.0.0.0", + "port": 1025, + "ignoreTLS": true }, "mongodb": "mongodb://localhost:27017/hc_api", "authentication": { diff --git a/config/local.example.json b/config/local.example.json index d18203b..a7d62cf 100644 --- a/config/local.example.json +++ b/config/local.example.json @@ -1,20 +1,6 @@ { - "host": "localhost", - "port": 3030, - "baseURL": "http://localhost:3030", - "frontURL": "http://localhost:3000", - "smtpConfig": { - "host": "0.0.0.0", - "port": 1025, - "ignoreTLS": true - }, - "thumbor": { - "url": "", - "key": "" - }, "seeder": { "runOnInit": true, "dropDatabase": false - }, - "defaultEmail": "no-reply@human-connection.org" + } } diff --git a/config/test.json b/config/test.json index 6bda5b5..5825f80 100644 --- a/config/test.json +++ b/config/test.json @@ -1,14 +1,5 @@ { "port": 3031, "baseURL": "http://localhost:3031", - "seeder": { - "runOnInit": false, - "dropDatabase": false - }, - "smtpConfig": { - "host": "0.0.0.0", - "port": 1025, - "ignoreTLS": true - }, "mongodb": "mongodb://localhost:27017/hc_api_test" } diff --git a/server/index.js b/server/index.js index f56069c..e2f9344 100644 --- a/server/index.js +++ b/server/index.js @@ -2,12 +2,6 @@ const fs = require('fs-extra'); const path = require('path'); -// setup local env is not available -let configDir = path.resolve('config'); -if (process.env.NODE_ENV !== 'production' && !fs.existsSync(configDir + '/local.json')) { - fs.copySync(configDir + '/local.example.json', configDir + '/local.json'); -} - const app = require('./app'); const port = app.get('port'); const host = app.get('host'); From 36069fd207718473490bf6bddd0eebcd5bab0241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Sat, 11 Aug 2018 14:06:53 +0200 Subject: [PATCH 03/20] Update README Remove obvious documentation --- README.md | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index fb842b5..fbf6fb0 100644 --- a/README.md +++ b/README.md @@ -35,14 +35,20 @@ Getting up and running is as easy as 1, 2, 3, 4 ... 5. $ cd ./API $ yarn ``` +4. Setup database seeder for local development (recommended) -4. Setup local mailserver (optional) + Run + ```sh + cp config/local.example.json config/local.json + ``` + +5. Setup local mailserver (optional) > **Note:** > *You only have to start that mailserver when you want to register, reset your password or test emails in any form, it > does not affect the rest of the application.* - Copy `config/local.example.json` to `config/local.json` and install the [MailDev](https://github.com/djfarrelly/MailDev) + Install the [MailDev](https://github.com/djfarrelly/MailDev) server to catch all sent emails in a nice web interface. ``` bash @@ -57,7 +63,7 @@ Getting up and running is as easy as 1, 2, 3, 4 ... 5. You could also insert your smtp credentials into the local.json but that is not recommended as all emails would be sent to the given addresses which should not happen in development. -5. Start server +6. Start server Make sure that the `data` folder exists according to the `mongod --dbpath` in `package.json` to write the data into, then start the server: ``` bash @@ -81,7 +87,7 @@ Getting up and running is as easy as 1, 2, 3, 4 ... 5. If you did it right it will seed some fake data for you and downloads some images and avatar for faster development. Now you should be able to list some post at [http://localhost:3030/contributions](http://localhost:3030/contributions) -6. Setup and Start Thumbnail Service (optional) +7. Setup and Start Thumbnail Service (optional) We are using [Thumbor](https://github.com/thumbor/thumbor) as a Thumbnail Microservice. You can install it locally if you like but this is totally optional. @@ -97,14 +103,7 @@ Getting up and running is as easy as 1, 2, 3, 4 ... 5. If you need to configure anything you can do so inside the `config/local.json` file. For that the `config/local.example.json` will contain always a minimal setup to get it working. -If, f.ex., you want to change listen address, port or URL, you can do so. Entries in the `config/local.json` will override entries in the `config/default.json`. - -**Note on the seeder configuration** -The seeder configuration has two properties: -- **dropDatabase:** drop the whole database on (re)start. -- **runOnInit:** run the seeder always on server (re)start (when database is empty). - -> **Note** *You can switch the `dropDatabase` entry after seeding and it will persist the seeded data.* +E.g. if you want to change listen address, port or URL, you can do so. Entries in the `config/local.json` will override entries in the `config/default.json`. ## Testing From 2b00bac2332be3521a8a04b58e3676fb811c4488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Sat, 11 Aug 2018 14:23:47 +0200 Subject: [PATCH 04/20] Remove cucumber.json altogether * Start and configure processes in with NODE_ENV in package.json * Remove obsolete step definitions --- config/cucumber.json | 5 ----- features/api/post.feature | 3 +-- features/api/usersettings.feature | 3 +-- features/env/database.js | 1 - features/step_definitions/steps.js | 13 +------------ package.json | 4 ++-- 6 files changed, 5 insertions(+), 24 deletions(-) delete mode 100644 config/cucumber.json diff --git a/config/cucumber.json b/config/cucumber.json deleted file mode 100644 index 5825f80..0000000 --- a/config/cucumber.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "port": 3031, - "baseURL": "http://localhost:3031", - "mongodb": "mongodb://localhost:27017/hc_api_test" -} diff --git a/features/api/post.feature b/features/api/post.feature index cb3ae79..6667374 100644 --- a/features/api/post.feature +++ b/features/api/post.feature @@ -5,8 +5,7 @@ Feature: Import a post from an organization and publish it in Human Connection Background: - Given the Human Connection API is up and running - And there is a user in Human Connection with these credentials: + Given there is a user in Human Connection with these credentials: | email | password | | user@example.com | 1234 | diff --git a/features/api/usersettings.feature b/features/api/usersettings.feature index ce46b41..98f0389 100644 --- a/features/api/usersettings.feature +++ b/features/api/usersettings.feature @@ -4,8 +4,7 @@ Feature: Save current newsfeed filters to usersettings In order to see the same selection of content next time I log in Background: - Given the Human Connection API is up and running - And there is a user in Human Connection with these credentials: + Given there is a user in Human Connection with these credentials: | email | password | isVerified | | user@example.com | 1234 | true | diff --git a/features/env/database.js b/features/env/database.js index 281dc64..61333a3 100644 --- a/features/env/database.js +++ b/features/env/database.js @@ -1,7 +1,6 @@ /* eslint no-console: off */ const { Before, AfterAll, setWorldConstructor } = require('cucumber'); -process.env.NODE_ENV = 'test'; // write into the test database const backendApp = require('../../server/app'); function CustomWorld() { diff --git a/features/step_definitions/steps.js b/features/step_definitions/steps.js index 28964cf..da1c0e4 100644 --- a/features/step_definitions/steps.js +++ b/features/step_definitions/steps.js @@ -6,7 +6,7 @@ const fetch = require('node-fetch'); const { expect } = require('chai'); const waitOn = require('wait-on'); -const hcBackendUrl = 'http://localhost:3030'; +const hcBackendUrl = 'http://localhost:3031'; let currentUser; let currentUserPassword; @@ -50,17 +50,6 @@ function postRequest(route, body, callback) { }); } -Given(/^the Human Connection API is up and running(?: on "http:\/\/localhost:3030")?/, (callback) => { - waitOn({ resources: ['tcp:3030'], timeout: 30000 }, (err) => { - if (err) throw (err); - return callback(); - }); -}); - -Given('there is a 3rd party application running, e.g. \'Democracy\'', () => { - // Just documentation -}); - Given('there is a user in Human Connection with these credentials:', function (dataTable) { const params = dataTable.hashes()[0]; currentUserPassword = params.password; diff --git a/package.json b/package.json index 9886ef5..f21d163 100644 --- a/package.json +++ b/package.json @@ -46,8 +46,8 @@ "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/\"", "mocha": "npm run clear && $npm_package_config_mocha", "mocha:mongo": "$npm_package_config_concurrently '$npm_package_config_mongoDev &>/dev/null' 'wait-on tcp:27017 && npm run mocha'", - "cucumber": "npm run clear && concurrently --kill-others --success first 'cross-env NODE_ENV=test node server/' 'wait-on tcp:3030 && cross-env NODE_ENV=test cucumber-js'", - "cucumber:mongo": "npm run clear && concurrently --kill-others --success first '$npm_package_config_mongoDev &>/dev/null || sleep infinity' 'wait-on tcp:27017 && cross-env NODE_ENV=test node server/' 'wait-on tcp:3030 && cross-env NODE_ENV=test cucumber-js'" + "cucumber": "npm run clear && concurrently --kill-others --success first 'cross-env NODE_ENV=test node server/' 'wait-on tcp:3031 && cross-env NODE_ENV=test cucumber-js'", + "cucumber:mongo": "npm run clear && concurrently --kill-others --success first '$npm_package_config_mongoDev &>/dev/null || sleep infinity' 'wait-on tcp:27017 && cross-env NODE_ENV=test node server/' 'wait-on tcp:3031 && cross-env NODE_ENV=test cucumber-js'" }, "config": { "mongoDev": "mongod --dbpath data --quiet", From 276bffea025f8187a3fdd58645aa5de42143caee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Sat, 11 Aug 2018 14:41:15 +0200 Subject: [PATCH 05/20] Run eslint --- features/step_definitions/steps.js | 1 - server/index.js | 3 --- 2 files changed, 4 deletions(-) diff --git a/features/step_definitions/steps.js b/features/step_definitions/steps.js index da1c0e4..385a3b3 100644 --- a/features/step_definitions/steps.js +++ b/features/step_definitions/steps.js @@ -4,7 +4,6 @@ const { Given, When, Then } = require('cucumber'); const fetch = require('node-fetch'); const { expect } = require('chai'); -const waitOn = require('wait-on'); const hcBackendUrl = 'http://localhost:3031'; diff --git a/server/index.js b/server/index.js index e2f9344..de2061f 100644 --- a/server/index.js +++ b/server/index.js @@ -1,7 +1,4 @@ /* eslint-disable no-console */ -const fs = require('fs-extra'); -const path = require('path'); - const app = require('./app'); const port = app.get('port'); const host = app.get('host'); From b1f0ad810a6a4fef18714626a86ad6a6144c5e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Sat, 11 Aug 2018 14:44:52 +0200 Subject: [PATCH 06/20] Fix .travis.yml --- .travis.yml | 4 +--- package.json | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index c99ea03..f0ae5e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,9 +22,7 @@ jobs: - script: - yarn install --frozen-lockfile --non-interactive - yarn add codacy-coverage - - yarn run eslint - - cp config/cucumber.json config/local.json - - yarn run test:coverage + - yarn run ci - cat ./coverage/lcov.info | codacy-coverage after_success: diff --git a/package.json b/package.json index f21d163..0e5cd8c 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "yarn": ">= 1.3.0" }, "scripts": { + "ci": "yarn run eslint && yarn run test:coverage", "clear": "rm -Rf tmp", "test": "npm run mocha && npm run cucumber", "test:coverage": "nyc --reporter=lcovonly --reporter=text-summary npm run test", From bf5919646560e38f6717bd0e9e14c60038b625b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Sat, 11 Aug 2018 14:51:56 +0200 Subject: [PATCH 07/20] Remove traces of npm - we're using yarn now --- README.md | 4 ++-- package.json | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index fbf6fb0..f3a0220 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Getting up and running is as easy as 1, 2, 3, 4 ... 5. ``` bash # install mail dev (only has to be done once) - $ npm install -g maildev + $ yarn global add maildev # start the server, it will output the web url # which normally is http://localhost:1080 @@ -114,7 +114,7 @@ Simply run `yarn test` and all your tests in the `test/` directory will be run. Feathers has a powerful command line interface. Here are a few things it can do: ``` bash -$ npm install -g feathers-cli # Install Feathers CLI +$ yarn global add feathers-cli # Install Feathers CLI $ feathers generate service # Generate a new Service $ feathers generate hook # Generate a new Hook diff --git a/package.json b/package.json index 0e5cd8c..e5f928c 100644 --- a/package.json +++ b/package.json @@ -35,20 +35,20 @@ "scripts": { "ci": "yarn run eslint && yarn run test:coverage", "clear": "rm -Rf tmp", - "test": "npm run mocha && npm run cucumber", - "test:coverage": "nyc --reporter=lcovonly --reporter=text-summary npm run test", - "test:mongo": "npm run eslint && cross-env NODE_ENV=test && nyc --reporter=lcovonly --reporter=text-summary npm run mocha:mongo", + "test": "yarn run mocha && yarn run cucumber", + "test:coverage": "nyc --reporter=lcovonly --reporter=text-summary yarn run test", + "test:mongo": "yarn run eslint && cross-env NODE_ENV=test && nyc --reporter=lcovonly --reporter=text-summary yarn run mocha:mongo", "eslint": "eslint server/. test/. features/. --config .eslintrc.json", "start": "concurrently 'mongod' 'wait-on tcp:27017 && cross-env NODE_ENV=production node server/'", - "dev:debug": "npm run clear && concurrently '$npm_package_config_mongoDev &>/dev/null' 'wait-on tcp:27017 && cross-env DEBUG=feathers && cross-env NODE_ENV=development nodemon --inspect server/'", - "dev": "npm run clear && concurrently '$npm_package_config_mongoDev &>/dev/null' 'wait-on tcp:27017 && cross-env DEBUG=feathers && cross-env NODE_ENV=development nodemon server/'", + "dev:debug": "yarn run clear && concurrently '$npm_package_config_mongoDev &>/dev/null' 'wait-on tcp:27017 && cross-env DEBUG=feathers && cross-env NODE_ENV=development nodemon --inspect server/'", + "dev": "yarn run clear && concurrently '$npm_package_config_mongoDev &>/dev/null' 'wait-on tcp:27017 && cross-env DEBUG=feathers && cross-env NODE_ENV=development nodemon server/'", "dev:local": "sh scripts/run-local.sh", "dev:noseed": "concurrently 'mongod --dbpath data' 'wait-on tcp:27017 && NODE_ENV=development DEBUG=feathers nodemon server/'", - "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/\"", - "mocha": "npm run clear && $npm_package_config_mocha", - "mocha:mongo": "$npm_package_config_concurrently '$npm_package_config_mongoDev &>/dev/null' 'wait-on tcp:27017 && npm run mocha'", - "cucumber": "npm run clear && concurrently --kill-others --success first 'cross-env NODE_ENV=test node server/' 'wait-on tcp:3031 && cross-env NODE_ENV=test cucumber-js'", - "cucumber:mongo": "npm run clear && concurrently --kill-others --success first '$npm_package_config_mongoDev &>/dev/null || sleep infinity' 'wait-on tcp:27017 && cross-env NODE_ENV=test node server/' 'wait-on tcp:3031 && cross-env NODE_ENV=test cucumber-js'" + "dev:win": "yarn run clear && concurrently \"mongod --dbpath /data/db\" \"wait-on tcp:27017&&cross-env NODE_ENV=development&&cross-env DEBUG=feathers&& nodemon --inspect server/\"", + "mocha": "yarn run clear && $npm_package_config_mocha", + "mocha:mongo": "$npm_package_config_concurrently '$npm_package_config_mongoDev &>/dev/null' 'wait-on tcp:27017 && yarn run mocha'", + "cucumber": "yarn run clear && concurrently --kill-others --success first 'cross-env NODE_ENV=test node server/' 'wait-on tcp:3031 && cross-env NODE_ENV=test cucumber-js'", + "cucumber:mongo": "yarn run clear && concurrently --kill-others --success first '$npm_package_config_mongoDev &>/dev/null || sleep infinity' 'wait-on tcp:27017 && cross-env NODE_ENV=test node server/' 'wait-on tcp:3031 && cross-env NODE_ENV=test cucumber-js'" }, "config": { "mongoDev": "mongod --dbpath data --quiet", From 62f7fe8e273d63d77ea11537d77fec2aff9afeb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Sat, 11 Aug 2018 15:18:29 +0200 Subject: [PATCH 08/20] Do away with most yarn run scripts. If you don't have a background process for mongo, how much of an effort is it to open a terminal? --- README.md | 81 +++++++++++++++++++++++++++++++--------------------- package.json | 15 ++++------ 2 files changed, 53 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index f3a0220..878b0f2 100644 --- a/README.md +++ b/README.md @@ -17,13 +17,13 @@ The API for a better world. More information under [human-connection.org](https: > **Note:** This is only the API part of Human-Connection, you have to also checkout the [WebApp](https://github.com/Human-Connection/WebApp) which uses this API. -## Development +## Local installation > we recommand to install the project locally for the best development ease and performance Getting up and running is as easy as 1, 2, 3, 4 ... 5. -1. Make sure you have [NodeJS](https://nodejs.org/), [yarn](https://yarnpkg.com), [mongoDB](https://www.mongodb.com/download-center#community) installed. +1. Make sure you have a recent version of [NodeJS](https://nodejs.org/), [yarn](https://yarnpkg.com) and [mongoDB](https://www.mongodb.com/download-center#community) installed. 2. Clone this repo ``` bash @@ -43,71 +43,86 @@ Getting up and running is as easy as 1, 2, 3, 4 ... 5. ``` 5. Setup local mailserver (optional) - - > **Note:** + + > **Note:** > *You only have to start that mailserver when you want to register, reset your password or test emails in any form, it > does not affect the rest of the application.* - + Install the [MailDev](https://github.com/djfarrelly/MailDev) server to catch all sent emails in a nice web interface. - + ``` bash # install mail dev (only has to be done once) $ yarn global add maildev - - # start the server, it will output the web url + + # start the server, it will output the web url # which normally is http://localhost:1080 $ maildev ``` - + You could also insert your smtp credentials into the local.json but that is not recommended as all emails would be sent to the given addresses which should not happen in development. - + 6. Start server - Make sure that the `data` folder exists according to the `mongod --dbpath` in `package.json` to write the data into, then start the server: + You don't have a background process running for mongodb? + Just open another terminal and run: + + ```bash + # open up another terminal and run: + $ yarn run mongo + # or if you are on windows, run: + $ yarn run mongo:win + ``` + + Start the API server with the following commands: ``` bash - # start mongodb, feathers and seed database $ yarn dev - $ yarn dev:win if you're on windows - # start mongodb, feathers without seeding the database - $ yarn dev:noseed - - # start mongodb, feathers for production + # without hot reload $ yarn start + # you can customize the environment like this: + $ NODE_ENV=production yarn start ``` - > ##### IMPORTANT for WIN users: + > ##### IMPORTANT for WIN users: > - make sure you have mongo bin directory added to your PATH - > - if you picked another data directory during mongodb setup make sure - > to change package.json scripts section for key "dev:win" so it points to - > the proper path. Otherwise you will get missing data path errors from mongodb. - - If you did it right it will seed some fake data for you and downloads some images and avatar for faster development. - Now you should be able to list some post at [http://localhost:3030/contributions](http://localhost:3030/contributions) + + Now, your API should be running at [http://localhost:3030](http://localhost:3030). + If you seeded your database, you will see some contributions at [http://localhost:3030/contributions](http://localhost:3030/contributions). 7. Setup and Start Thumbnail Service (optional) We are using [Thumbor](https://github.com/thumbor/thumbor) as a Thumbnail Microservice. You can install it locally if you like but this is totally optional. - + **Install OR use docker** - + - At first you have to [install](http://thumbor.readthedocs.io/en/latest/installing.html) it locally and start it in the console with `thumbor` **OR** run it with docker `docker run -p 8000:8000 apsl/thumbor` - Set the `thumbor.url` in `config/local.json` to `http://localhost:8888` (with docker `http://localhost:8000`) if not defined differently. The `thumbor.key` does not necessarily have to be defined, it just makes the URL more secure. - - > Do not forget to always start it if you choose that setup or otherwise you will not see any pictures at all. -## Local configuration + > Do not forget to always start it if you choose that setup or otherwise you will not see any pictures at all. -If you need to configure anything you can do so inside the `config/local.json` file. For that the `config/local.example.json` will contain always a minimal setup to get it working. +### Local configuration -E.g. if you want to change listen address, port or URL, you can do so. Entries in the `config/local.json` will override entries in the `config/default.json`. +You can override any default configuration in `config/local.json`. You can find +a list of availabe defaults in `config/default.json`. +See [node-config documentation](https://github.com/lorenwest/node-config/wiki/Configuration-Files) +for details. ## Testing -Simply run `yarn test` and all your tests in the `test/` directory will be run. +Run the entire test suite with: +```bash +yarn run test +``` + +If you want you can run specific tests: +```bash +yarn run mocha +yarn run cucumber +``` + ## Scaffolding @@ -128,7 +143,7 @@ For more information on all the framework related things visit [docs.feathersjs. The HC platform is documented in our [gitbook](https://www.gitbook.com/book/human-connection/documentation/) (work in progress). -## License +## License Copyright (c) 2018 [Human-Connection.org](https://human-connection.org) diff --git a/package.json b/package.json index e5f928c..fdf2d9b 100644 --- a/package.json +++ b/package.json @@ -35,24 +35,19 @@ "scripts": { "ci": "yarn run eslint && yarn run test:coverage", "clear": "rm -Rf tmp", + "mongo": "mongod --dbpath data --quiet", + "mongo:win": "mongod --dbpath /data/db --quiet", "test": "yarn run mocha && yarn run cucumber", "test:coverage": "nyc --reporter=lcovonly --reporter=text-summary yarn run test", - "test:mongo": "yarn run eslint && cross-env NODE_ENV=test && nyc --reporter=lcovonly --reporter=text-summary yarn run mocha:mongo", "eslint": "eslint server/. test/. features/. --config .eslintrc.json", - "start": "concurrently 'mongod' 'wait-on tcp:27017 && cross-env NODE_ENV=production node server/'", + "start": "node server/", "dev:debug": "yarn run clear && concurrently '$npm_package_config_mongoDev &>/dev/null' 'wait-on tcp:27017 && cross-env DEBUG=feathers && cross-env NODE_ENV=development nodemon --inspect server/'", "dev": "yarn run clear && concurrently '$npm_package_config_mongoDev &>/dev/null' 'wait-on tcp:27017 && cross-env DEBUG=feathers && cross-env NODE_ENV=development nodemon server/'", "dev:local": "sh scripts/run-local.sh", - "dev:noseed": "concurrently 'mongod --dbpath data' 'wait-on tcp:27017 && NODE_ENV=development DEBUG=feathers nodemon server/'", - "dev:win": "yarn run clear && concurrently \"mongod --dbpath /data/db\" \"wait-on tcp:27017&&cross-env NODE_ENV=development&&cross-env DEBUG=feathers&& nodemon --inspect server/\"", - "mocha": "yarn run clear && $npm_package_config_mocha", - "mocha:mongo": "$npm_package_config_concurrently '$npm_package_config_mongoDev &>/dev/null' 'wait-on tcp:27017 && yarn run mocha'", - "cucumber": "yarn run clear && concurrently --kill-others --success first 'cross-env NODE_ENV=test node server/' 'wait-on tcp:3031 && cross-env NODE_ENV=test cucumber-js'", - "cucumber:mongo": "yarn run clear && concurrently --kill-others --success first '$npm_package_config_mongoDev &>/dev/null || sleep infinity' 'wait-on tcp:27017 && cross-env NODE_ENV=test node server/' 'wait-on tcp:3031 && cross-env NODE_ENV=test cucumber-js'" + "mocha": "cross-env NODE_ENV=test node_modules/mocha/bin/_mocha test/ --recursive --timeout 10000 --exit", + "cucumber": "yarn run clear && concurrently --kill-others --success first 'cross-env NODE_ENV=test node server/' 'wait-on tcp:3031 && cross-env NODE_ENV=test cucumber-js'" }, "config": { - "mongoDev": "mongod --dbpath data --quiet", - "mocha": "cross-env NODE_ENV=test node_modules/mocha/bin/_mocha test/ --recursive --timeout 10000 --exit", "concurrently": "concurrently --kill-others --success first" }, "dependencies": { From 620d175a29064d4122062201c8f3b1709b3aa313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Sat, 11 Aug 2018 16:23:01 +0200 Subject: [PATCH 09/20] Simplify package.json, remove dev:local script The script was assuming a POSIX shell and a command `ifconfig` available on the system. I don't have either. I guess we can just remove it. You can access the server from the local network if you override `host` in your `config/local.json`. This is much better in my opinion. --- package.json | 10 +++------- scripts/run-local.sh | 5 ----- 2 files changed, 3 insertions(+), 12 deletions(-) delete mode 100644 scripts/run-local.sh diff --git a/package.json b/package.json index fdf2d9b..81f96af 100644 --- a/package.json +++ b/package.json @@ -41,14 +41,10 @@ "test:coverage": "nyc --reporter=lcovonly --reporter=text-summary yarn run test", "eslint": "eslint server/. test/. features/. --config .eslintrc.json", "start": "node server/", - "dev:debug": "yarn run clear && concurrently '$npm_package_config_mongoDev &>/dev/null' 'wait-on tcp:27017 && cross-env DEBUG=feathers && cross-env NODE_ENV=development nodemon --inspect server/'", - "dev": "yarn run clear && concurrently '$npm_package_config_mongoDev &>/dev/null' 'wait-on tcp:27017 && cross-env DEBUG=feathers && cross-env NODE_ENV=development nodemon server/'", - "dev:local": "sh scripts/run-local.sh", + "dev": "cross-env DEBUG=feathers && nodemon server/", + "dev:debug": "cross-env DEBUG=feathers nodemon --inspect server/", "mocha": "cross-env NODE_ENV=test node_modules/mocha/bin/_mocha test/ --recursive --timeout 10000 --exit", - "cucumber": "yarn run clear && concurrently --kill-others --success first 'cross-env NODE_ENV=test node server/' 'wait-on tcp:3031 && cross-env NODE_ENV=test cucumber-js'" - }, - "config": { - "concurrently": "concurrently --kill-others --success first" + "cucumber": "concurrently --kill-others --success first 'cross-env NODE_ENV=test node server/' 'wait-on tcp:3031 && cross-env NODE_ENV=test cucumber-js'" }, "dependencies": { "@feathersjs/authentication": "^2.1.7", diff --git a/scripts/run-local.sh b/scripts/run-local.sh deleted file mode 100644 index 46a9ee2..0000000 --- a/scripts/run-local.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -# start app on the local network -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'); -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 From 6b1819f68a651039bd6ff570a71268e0b4dedab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Sat, 11 Aug 2018 16:56:31 +0200 Subject: [PATCH 10/20] Testing maildev, seems to work except: https://github.com/Human-Connection/API/pull/147#issuecomment-412280080 --- config/default.json | 1 + package.json | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/config/default.json b/config/default.json index 60810d2..76669a2 100644 --- a/config/default.json +++ b/config/default.json @@ -20,6 +20,7 @@ "runOnInit": false, "dropDatabase": false }, + "defaultEmail": "no-reply@human-connection.org", "smtpConfig": { "host": "0.0.0.0", "port": 1025, diff --git a/package.json b/package.json index 81f96af..70c11d1 100644 --- a/package.json +++ b/package.json @@ -41,8 +41,8 @@ "test:coverage": "nyc --reporter=lcovonly --reporter=text-summary yarn run test", "eslint": "eslint server/. test/. features/. --config .eslintrc.json", "start": "node server/", - "dev": "cross-env DEBUG=feathers && nodemon server/", - "dev:debug": "cross-env DEBUG=feathers nodemon --inspect server/", + "dev": "cross-env DEBUG=feathers* && nodemon server/", + "dev:debug": "cross-env DEBUG=feathers* nodemon --inspect server/", "mocha": "cross-env NODE_ENV=test node_modules/mocha/bin/_mocha test/ --recursive --timeout 10000 --exit", "cucumber": "concurrently --kill-others --success first 'cross-env NODE_ENV=test node server/' 'wait-on tcp:3031 && cross-env NODE_ENV=test cucumber-js'" }, From 7ca2ec66b2236ecf0d9efb38cb410cc2bbc8275a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Sun, 12 Aug 2018 00:13:49 +0200 Subject: [PATCH 11/20] Faster global add on travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f0ae5e1..1abf30e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ jobs: - docker build -t humanconnection/api-feathers . - script: - yarn install --frozen-lockfile --non-interactive - - yarn add codacy-coverage + - yarn global add codacy-coverage - yarn run ci - cat ./coverage/lcov.info | codacy-coverage From f6679e7e53c1e15466d1c4146fb47b170ec6ed29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Sun, 12 Aug 2018 11:56:02 +0200 Subject: [PATCH 12/20] Minor formatting in README --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 878b0f2..4b04063 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Getting up and running is as easy as 1, 2, 3, 4 ... 5. Run ```sh - cp config/local.example.json config/local.json + $ cp config/local.example.json config/local.json ``` 5. Setup local mailserver (optional) @@ -74,6 +74,8 @@ Getting up and running is as easy as 1, 2, 3, 4 ... 5. # or if you are on windows, run: $ yarn run mongo:win ``` + > ##### IMPORTANT for Windows users: + > - make sure you have mongo bin directory added to your PATH Start the API server with the following commands: ``` bash @@ -85,8 +87,6 @@ Getting up and running is as easy as 1, 2, 3, 4 ... 5. $ NODE_ENV=production yarn start ``` - > ##### IMPORTANT for WIN users: - > - make sure you have mongo bin directory added to your PATH Now, your API should be running at [http://localhost:3030](http://localhost:3030). If you seeded your database, you will see some contributions at [http://localhost:3030/contributions](http://localhost:3030/contributions). @@ -114,13 +114,13 @@ for details. Run the entire test suite with: ```bash -yarn run test +$ yarn run test ``` If you want you can run specific tests: ```bash -yarn run mocha -yarn run cucumber +$ yarn run mocha +$ yarn run cucumber ``` From 59a93a8ff662a864c96f4d02c4ca1eef86425ec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Tue, 14 Aug 2018 14:38:45 +0200 Subject: [PATCH 13/20] Better error message on initial mongodb connect --- server/mongoose.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/mongoose.js b/server/mongoose.js index 60bc6d7..94fc4c0 100644 --- a/server/mongoose.js +++ b/server/mongoose.js @@ -5,13 +5,14 @@ const path = require('path'); module.exports = function () { const app = this; + mongoose.Promise = global.Promise; mongoose.connect(app.get('mongodb'), { useMongoClient: true, autoReconnect: true, keepAlive: 1, connectTimeoutMS: 10000, socketTimeoutMS: 10000 - }, function () { + }).then(() => { if (process.env.NODE_ENV !== 'production' && app.get('seeder').dropDatabase === true) { mongoose.connection.dropDatabase().then(() => { app.debug('>>>>>> DROPED DATABASE <<<<<<'); @@ -25,7 +26,8 @@ module.exports = function () { } else { app.emit('mongooseInit'); } + },(err) => { + console.log(err); }); - mongoose.Promise = global.Promise; app.set('mongooseClient', mongoose); }; From cbdbaf07c8eb25f42e223e225f97576d3d1524dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Sun, 12 Aug 2018 00:34:05 +0200 Subject: [PATCH 14/20] Using standard mocha command is just fine --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 70c11d1..b9beda2 100644 --- a/package.json +++ b/package.json @@ -42,8 +42,8 @@ "eslint": "eslint server/. test/. features/. --config .eslintrc.json", "start": "node server/", "dev": "cross-env DEBUG=feathers* && nodemon server/", - "dev:debug": "cross-env DEBUG=feathers* nodemon --inspect server/", - "mocha": "cross-env NODE_ENV=test node_modules/mocha/bin/_mocha test/ --recursive --timeout 10000 --exit", + "dev:debug": "cross-env DEBUG=feathers* nodemon --inspect=0.0.0.0:9229 server/", + "mocha": "cross-env NODE_ENV=test mocha --recursive --timeout 10000 --exit", "cucumber": "concurrently --kill-others --success first 'cross-env NODE_ENV=test node server/' 'wait-on tcp:3031 && cross-env NODE_ENV=test cucumber-js'" }, "dependencies": { From b8b1d159b2b10caa96ae1d64b5999efe22f6ee49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Tue, 14 Aug 2018 16:28:05 +0200 Subject: [PATCH 15/20] Run clear before mocha (rendered email templates) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b9beda2..a01a933 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "start": "node server/", "dev": "cross-env DEBUG=feathers* && nodemon server/", "dev:debug": "cross-env DEBUG=feathers* nodemon --inspect=0.0.0.0:9229 server/", - "mocha": "cross-env NODE_ENV=test mocha --recursive --timeout 10000 --exit", + "mocha": "yarn run clear && cross-env NODE_ENV=test mocha --recursive --timeout 10000 --exit", "cucumber": "concurrently --kill-others --success first 'cross-env NODE_ENV=test node server/' 'wait-on tcp:3031 && cross-env NODE_ENV=test cucumber-js'" }, "dependencies": { From bb2c1eb2071c3c5082eb09dd8f97969d6ff3c51c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Tue, 14 Aug 2018 16:44:46 +0200 Subject: [PATCH 16/20] Fix eslint --- server/mongoose.js | 1 + 1 file changed, 1 insertion(+) diff --git a/server/mongoose.js b/server/mongoose.js index 94fc4c0..f7a5faf 100644 --- a/server/mongoose.js +++ b/server/mongoose.js @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ const mongoose = require('mongoose'); const fs = require('fs-extra'); const path = require('path'); From fa1ae5766af1a494dd8da5759a117c833bb92905 Mon Sep 17 00:00:00 2001 From: Grzegorz Leoniec Date: Tue, 14 Aug 2018 21:20:10 +0200 Subject: [PATCH 17/20] fixed debug messages for dev command --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a01a933..fa3873f 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "test:coverage": "nyc --reporter=lcovonly --reporter=text-summary yarn run test", "eslint": "eslint server/. test/. features/. --config .eslintrc.json", "start": "node server/", - "dev": "cross-env DEBUG=feathers* && nodemon server/", + "dev": "cross-env DEBUG=feathers* nodemon server/", "dev:debug": "cross-env DEBUG=feathers* nodemon --inspect=0.0.0.0:9229 server/", "mocha": "yarn run clear && cross-env NODE_ENV=test mocha --recursive --timeout 10000 --exit", "cucumber": "concurrently --kill-others --success first 'cross-env NODE_ENV=test node server/' 'wait-on tcp:3031 && cross-env NODE_ENV=test cucumber-js'" From 5fa59260f297276df66f4ece362160251a72c23f Mon Sep 17 00:00:00 2001 From: Grzegorz Leoniec Date: Tue, 14 Aug 2018 21:22:18 +0200 Subject: [PATCH 18/20] fixed minor readme styling --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 4b04063..04be572 100644 --- a/README.md +++ b/README.md @@ -65,19 +65,19 @@ Getting up and running is as easy as 1, 2, 3, 4 ... 5. 6. Start server - You don't have a background process running for mongodb? - Just open another terminal and run: - - ```bash - # open up another terminal and run: - $ yarn run mongo - # or if you are on windows, run: - $ yarn run mongo:win - ``` + You don't have a background process running for mongodb? + Just open another terminal and run: + + ```bash + # open up another terminal and run: + $ yarn run mongo + # or if you are on windows, run: + $ yarn run mongo:win + ``` > ##### IMPORTANT for Windows users: > - make sure you have mongo bin directory added to your PATH - Start the API server with the following commands: + Start the API server with the following commands: ``` bash $ yarn dev From 9130baaf774f97a01949f15761d0e5bd78d254b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Thu, 16 Aug 2018 23:32:46 +0200 Subject: [PATCH 19/20] Add hint how to visit server on mobile --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 04be572..deffa7a 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,17 @@ a list of availabe defaults in `config/default.json`. See [node-config documentation](https://github.com/lorenwest/node-config/wiki/Configuration-Files) for details. +E.g. if you want to access the server from your mobile over WiFi, you should +replace `localhost` in your settings with your IP address in the local network: +```json +{ + "host": "192.168.188.22", + "baseURL": "http://192.168.188.22:3030", + "frontURL": "http://192.168.188.22:3000" +} + +``` + ## Testing Run the entire test suite with: From c58a5f561bfd387f857278006283a35e13b6ca89 Mon Sep 17 00:00:00 2001 From: Grzegorz Leoniec Date: Fri, 24 Aug 2018 17:48:07 +0200 Subject: [PATCH 20/20] fixed default config to allow image display when thumbor is not set up --- config/default.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/default.json b/config/default.json index 76669a2..3fb5557 100644 --- a/config/default.json +++ b/config/default.json @@ -11,8 +11,8 @@ "max": 100 }, "thumbor": { - "url": "", - "key": "" + "url": false, + "key": false }, "apiSecret": "TE9TqAk2xK[9EFJL", "sentry": {},