Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ jobs:
- docker build -t humanconnection/api-feathers .
- 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 global add codacy-coverage
- yarn run ci
- cat ./coverage/lcov.info | codacy-coverage

after_success:
Expand Down
115 changes: 70 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,87 +35,112 @@ 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)

> **Note:**
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
# install mail dev (only has to be done once)
$ npm install -g maildev
# start the server, it will output the web url
$ yarn global add maildev

# 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.

5. 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:
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
```
> ##### IMPORTANT for Windows users:
> - make sure you have mongo bin directory added to your PATH

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:
> - 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)

6. Setup and Start Thumbnail Service (optional)
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

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`.
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.

**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).
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"
}

> **Note** *You can switch the `dropDatabase` entry after seeding and it will persist the seeded data.*
```

## 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

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
Expand All @@ -129,7 +154,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)

Expand Down
20 changes: 0 additions & 20 deletions config/cucumber.json

This file was deleted.

14 changes: 10 additions & 4 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@
"max": 100
},
"thumbor": {
"url": "",
"key": ""
"url": false,
"key": false
},
"apiSecret": "TE9TqAk2xK[9EFJL",
"sentry": {},
"seeder": {
"runOnInit": true,
"dropDatabase": true
"runOnInit": false,
"dropDatabase": false
},
"defaultEmail": "no-reply@human-connection.org",
"smtpConfig": {
"host": "0.0.0.0",
"port": 1025,
"ignoreTLS": true
},
"mongodb": "mongodb://localhost:27017/hc_api",
"authentication": {
Expand Down
16 changes: 1 addition & 15 deletions config/local.example.json
Original file line number Diff line number Diff line change
@@ -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-replay@human-connection.org"
}
}
9 changes: 0 additions & 9 deletions config/test.json
Original file line number Diff line number Diff line change
@@ -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"
}
3 changes: 1 addition & 2 deletions features/api/post.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down
3 changes: 1 addition & 2 deletions features/api/usersettings.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down
1 change: 0 additions & 1 deletion features/env/database.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
14 changes: 1 addition & 13 deletions features/step_definitions/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
const { Given, When, Then } = require('cucumber');
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;
Expand Down Expand Up @@ -50,17 +49,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;
Expand Down
28 changes: 10 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,18 @@
"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",
"test:mongo": "npm run eslint && cross-env NODE_ENV=test && nyc --reporter=lcovonly --reporter=text-summary npm run mocha:mongo",
"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",
"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:local": "sh scripts/run-local.sh",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please re-add the dev:local command for mobile development?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script uses ifconfig to set some environment variables with the local IP address. E.g. I don't have ifconfig installed and the script fails silently. I find it much more convenient to set host in config/local.json to the local ip and just run yarn run dev. Can we keep scripts/run-local.sh deleted, please?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add some instructions in README.md if you like.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You missed the point of that script I think. It is getting your host ip to then start the app in your local network so you can access it from your mobile phone. It’s way more convenient then to write your ip into the local.config

But for me it’s fine to put it into the readme.

"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: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'"
},
"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"
"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": "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": {
"@feathersjs/authentication": "^2.1.7",
Expand Down
5 changes: 0 additions & 5 deletions scripts/run-local.sh

This file was deleted.

9 changes: 0 additions & 9 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
/* eslint-disable no-console */
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');
Expand Down
Loading