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

Commit b1254f3

Browse files
Merge pull request #147 from Human-Connection/improve_configuration
Improve configuration
2 parents 86ac186 + c58a5f5 commit b1254f3

File tree

14 files changed

+101
-149
lines changed

14 files changed

+101
-149
lines changed

.travis.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ jobs:
2121
- docker build -t humanconnection/api-feathers .
2222
- script:
2323
- yarn install --frozen-lockfile --non-interactive
24-
- yarn add codacy-coverage
25-
- yarn run eslint
26-
- cp config/cucumber.json config/local.json
27-
- yarn run test:coverage
24+
- yarn global add codacy-coverage
25+
- yarn run ci
2826
- cat ./coverage/lcov.info | codacy-coverage
2927

3028
after_success:

README.md

Lines changed: 70 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ The API for a better world. More information under [human-connection.org](https:
1717

1818
> **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.
1919
20-
## Development
20+
## Local installation
2121

2222
> we recommand to install the project locally for the best development ease and performance
2323
2424
Getting up and running is as easy as 1, 2, 3, 4 ... 5.
2525

26-
1. Make sure you have [NodeJS](https://nodejs.org/), [yarn](https://yarnpkg.com), [mongoDB](https://www.mongodb.com/download-center#community) installed.
26+
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.
2727

2828
2. Clone this repo
2929
``` bash
@@ -35,87 +35,112 @@ Getting up and running is as easy as 1, 2, 3, 4 ... 5.
3535
$ cd ./API
3636
$ yarn
3737
```
38+
4. Setup database seeder for local development (recommended)
3839

39-
4. Setup local mailserver (optional)
40-
41-
> **Note:**
40+
Run
41+
```sh
42+
$ cp config/local.example.json config/local.json
43+
```
44+
45+
5. Setup local mailserver (optional)
46+
47+
> **Note:**
4248
> *You only have to start that mailserver when you want to register, reset your password or test emails in any form, it
4349
> does not affect the rest of the application.*
44-
45-
Copy `config/local.example.json` to `config/local.json` and install the [MailDev](https://github.com/djfarrelly/MailDev)
50+
51+
Install the [MailDev](https://github.com/djfarrelly/MailDev)
4652
server to catch all sent emails in a nice web interface.
47-
53+
4854
``` bash
4955
# install mail dev (only has to be done once)
50-
$ npm install -g maildev
51-
52-
# start the server, it will output the web url
56+
$ yarn global add maildev
57+
58+
# start the server, it will output the web url
5359
# which normally is http://localhost:1080
5460
$ maildev
5561
```
56-
62+
5763
You could also insert your smtp credentials into the local.json but that is not recommended as all emails would be sent
5864
to the given addresses which should not happen in development.
59-
60-
5. Start server
6165

62-
Make sure that the `data` folder exists according to the `mongod --dbpath` in `package.json` to write the data into, then start the server:
66+
6. Start server
67+
68+
You don't have a background process running for mongodb?
69+
Just open another terminal and run:
70+
71+
```bash
72+
# open up another terminal and run:
73+
$ yarn run mongo
74+
# or if you are on windows, run:
75+
$ yarn run mongo:win
76+
```
77+
> ##### IMPORTANT for Windows users:
78+
> - make sure you have mongo bin directory added to your PATH
79+
80+
Start the API server with the following commands:
6381
``` bash
64-
# start mongodb, feathers and seed database
6582
$ yarn dev
66-
$ yarn dev:win if you're on windows
6783

68-
# start mongodb, feathers without seeding the database
69-
$ yarn dev:noseed
70-
71-
# start mongodb, feathers for production
84+
# without hot reload
7285
$ yarn start
86+
# you can customize the environment like this:
87+
$ NODE_ENV=production yarn start
7388
```
7489

75-
> ##### IMPORTANT for WIN users:
76-
> - make sure you have mongo bin directory added to your PATH
77-
> - if you picked another data directory during mongodb setup make sure
78-
> to change package.json scripts section for key "dev:win" so it points to
79-
> the proper path. Otherwise you will get missing data path errors from mongodb.
80-
81-
If you did it right it will seed some fake data for you and downloads some images and avatar for faster development.
82-
Now you should be able to list some post at [http://localhost:3030/contributions](http://localhost:3030/contributions)
8390

84-
6. Setup and Start Thumbnail Service (optional)
91+
Now, your API should be running at [http://localhost:3030](http://localhost:3030).
92+
If you seeded your database, you will see some contributions at [http://localhost:3030/contributions](http://localhost:3030/contributions).
93+
94+
7. Setup and Start Thumbnail Service (optional)
8595

8696
We are using [Thumbor](https://github.com/thumbor/thumbor) as a Thumbnail Microservice.
8797
You can install it locally if you like but this is totally optional.
88-
98+
8999
**Install OR use docker**
90-
100+
91101
- 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`
92102
- 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.
93-
94-
> Do not forget to always start it if you choose that setup or otherwise you will not see any pictures at all.
95103

96-
## Local configuration
104+
> Do not forget to always start it if you choose that setup or otherwise you will not see any pictures at all.
97105
98-
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.
106+
### Local configuration
99107

100-
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`.
108+
You can override any default configuration in `config/local.json`. You can find
109+
a list of availabe defaults in `config/default.json`.
110+
See [node-config documentation](https://github.com/lorenwest/node-config/wiki/Configuration-Files)
111+
for details.
101112

102-
**Note on the seeder configuration**
103-
The seeder configuration has two properties:
104-
- **dropDatabase:** drop the whole database on (re)start.
105-
- **runOnInit:** run the seeder always on server (re)start (when database is empty).
113+
E.g. if you want to access the server from your mobile over WiFi, you should
114+
replace `localhost` in your settings with your IP address in the local network:
115+
```json
116+
{
117+
"host": "192.168.188.22",
118+
"baseURL": "http://192.168.188.22:3030",
119+
"frontURL": "http://192.168.188.22:3000"
120+
}
106121

107-
> **Note** *You can switch the `dropDatabase` entry after seeding and it will persist the seeded data.*
122+
```
108123

109124
## Testing
110125

111-
Simply run `yarn test` and all your tests in the `test/` directory will be run.
126+
Run the entire test suite with:
127+
```bash
128+
$ yarn run test
129+
```
130+
131+
If you want you can run specific tests:
132+
```bash
133+
$ yarn run mocha
134+
$ yarn run cucumber
135+
```
136+
112137

113138
## Scaffolding
114139

115140
Feathers has a powerful command line interface. Here are a few things it can do:
116141

117142
``` bash
118-
$ npm install -g feathers-cli # Install Feathers CLI
143+
$ yarn global add feathers-cli # Install Feathers CLI
119144

120145
$ feathers generate service # Generate a new Service
121146
$ feathers generate hook # Generate a new Hook
@@ -129,7 +154,7 @@ For more information on all the framework related things visit [docs.feathersjs.
129154

130155
The HC platform is documented in our [gitbook](https://www.gitbook.com/book/human-connection/documentation/) (work in progress).
131156

132-
## License
157+
## License
133158

134159
Copyright (c) 2018 [Human-Connection.org](https://human-connection.org)
135160

config/cucumber.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

config/default.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,20 @@
1111
"max": 100
1212
},
1313
"thumbor": {
14-
"url": "",
15-
"key": ""
14+
"url": false,
15+
"key": false
1616
},
1717
"apiSecret": "TE9TqAk2xK[9EFJL",
1818
"sentry": {},
1919
"seeder": {
20-
"runOnInit": true,
21-
"dropDatabase": true
20+
"runOnInit": false,
21+
"dropDatabase": false
22+
},
23+
"defaultEmail": "[email protected]",
24+
"smtpConfig": {
25+
"host": "0.0.0.0",
26+
"port": 1025,
27+
"ignoreTLS": true
2228
},
2329
"mongodb": "mongodb://localhost:27017/hc_api",
2430
"authentication": {

config/local.example.json

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
{
2-
"host": "localhost",
3-
"port": 3030,
4-
"baseURL": "http://localhost:3030",
5-
"frontURL": "http://localhost:3000",
6-
"smtpConfig": {
7-
"host": "0.0.0.0",
8-
"port": 1025,
9-
"ignoreTLS": true
10-
},
11-
"thumbor": {
12-
"url": "",
13-
"key": ""
14-
},
152
"seeder": {
163
"runOnInit": true,
174
"dropDatabase": false
18-
},
19-
"defaultEmail": "[email protected]"
5+
}
206
}

config/test.json

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
{
22
"port": 3031,
33
"baseURL": "http://localhost:3031",
4-
"seeder": {
5-
"runOnInit": false,
6-
"dropDatabase": false
7-
},
8-
"smtpConfig": {
9-
"host": "0.0.0.0",
10-
"port": 1025,
11-
"ignoreTLS": true
12-
},
134
"mongodb": "mongodb://localhost:27017/hc_api_test"
145
}

features/api/post.feature

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ Feature: Import a post from an organization and publish it in Human Connection
55

66

77
Background:
8-
Given the Human Connection API is up and running
9-
And there is a user in Human Connection with these credentials:
8+
Given there is a user in Human Connection with these credentials:
109
| email | password |
1110
| user@example.com | 1234 |
1211

features/api/usersettings.feature

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ Feature: Save current newsfeed filters to usersettings
44
In order to see the same selection of content next time I log in
55

66
Background:
7-
Given the Human Connection API is up and running
8-
And there is a user in Human Connection with these credentials:
7+
Given there is a user in Human Connection with these credentials:
98
| email | password | isVerified |
109
| user@example.com | 1234 | true |
1110

features/env/database.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint no-console: off */
22
const { Before, AfterAll, setWorldConstructor } = require('cucumber');
33

4-
process.env.NODE_ENV = 'test'; // write into the test database
54
const backendApp = require('../../server/app');
65

76
function CustomWorld() {

features/step_definitions/steps.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
const { Given, When, Then } = require('cucumber');
55
const fetch = require('node-fetch');
66
const { expect } = require('chai');
7-
const waitOn = require('wait-on');
87

9-
const hcBackendUrl = 'http://localhost:3030';
8+
const hcBackendUrl = 'http://localhost:3031';
109

1110
let currentUser;
1211
let currentUserPassword;
@@ -50,17 +49,6 @@ function postRequest(route, body, callback) {
5049
});
5150
}
5251

53-
Given(/^the Human Connection API is up and running(?: on "http:\/\/localhost:3030")?/, (callback) => {
54-
waitOn({ resources: ['tcp:3030'], timeout: 30000 }, (err) => {
55-
if (err) throw (err);
56-
return callback();
57-
});
58-
});
59-
60-
Given('there is a 3rd party application running, e.g. \'Democracy\'', () => {
61-
// Just documentation
62-
});
63-
6452
Given('there is a user in Human Connection with these credentials:', function (dataTable) {
6553
const params = dataTable.hashes()[0];
6654
currentUserPassword = params.password;

0 commit comments

Comments
 (0)