You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+88-7Lines changed: 88 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ To find out more about the Clock of Change and Human Connection - the network be
11
11
* Express.js: We use the [Express.js](https://expressjs.com/en/) framework - a Node.js framework to help build web applications
12
12
* Nodemon: We use [Nodemon](https://nodemon.io/) for development - a handy replacement wrapper for Node.js that automatically restarts the application on file changes
13
13
* MySQL: We use [MySQL](https://www.mysql.com) as our relational database of choice to store our data
14
-
14
+
* MailHog: We use [MailHog](https://github.com/mailhog/MailHog) to debug and preview the email communication
15
15
16
16
## Project Structure & Components
17
17
@@ -21,7 +21,9 @@ To find out more about the Clock of Change and Human Connection - the network be
21
21
* core/: The core directory contains the most important files of the project like database, mailer, router and main controller
22
22
* core/entryController.js: Is the main controller for all the requests
23
23
* core/restapi.js: All routes can be found here, they will also be listed further down
24
+
* documentation/: Documentation for the Clock of Change API
24
25
* mails/: The mails directory holds the mail templates
26
+
* migrations/: Migrations for the database
25
27
* public/: The public directory is not used for now
26
28
27
29
@@ -31,25 +33,86 @@ We use MySQL for the COC API as our relational database.
31
33
Currently all of the database related code can be found in the `core/db.js` file.
32
34
This includes the credentials for the database (host, user, password and db name) and can be changed in this file.
33
35
34
-
TODO: Add description of tables
36
+
MySQL DB can be configured with the following environment variables:
37
+
38
+
| Variable | Description |
39
+
|--------------|-------------------------------|
40
+
|`MYSQL_HOST`| Host address for the database |
41
+
|`MYSQL_DB`| Database Name |
42
+
|`MYSQL_USER`| MySQL User |
43
+
|`MYSQL_PASS`| MySQL Password |
44
+
45
+
Currently we have two tables:
46
+
* apikeys: Contains the apikeys required to perform authorized API request
47
+
* entries: Stores the user entries for the Clock of Change
48
+
49
+
For more information about the tables, see the SQL dump of the tables at `documentation/tables.sql` .
35
50
36
51
**MAILER**
37
52
38
53
The code related to the mail system can be found in the file `core/mailer.js`.
39
54
For the mailer to work the smtp credentials need to be changed in this file as well.
40
55
Then the mailer will work and use the mail templates from `mails/entry/`
41
56
57
+
SMTP can be configured with the following environment variables:
58
+
59
+
| Variable | Description |
60
+
|--------------|-------------------------------|
61
+
|`MAIL_HOST`| Host address for the mailer |
62
+
|`MAIL_PORT`| Port number for the mailer |
63
+
|`MAIL_USER`| Mailer User |
64
+
|`MAIL_PASS`| Mailer Password |
65
+
66
+
67
+
68
+
To debug and preview the emails, we use [MailHog](https://github.com/mailhog/MailHog).
69
+
When installing the Clock of Change without Docker, you have to install MailHog manually (see link for details).
70
+
Then set the host address of MailHog in the Clock of Change API and use `1025` as the port number.
71
+
72
+
Assuming MailHog is running on localhost or you have chosen the Docker installation, you can debug and preview the mails under [http://localhost:8025/](http://localhost:8025/).
42
73
43
74
## Installation
44
75
45
76
**PREREQUESITES**
46
77
47
-
Before starting the installation you need to make sure you have the following tools installed:
48
-
* Git: You need to have Git installed. You can check this in the console with `git --help`. For installation instructions visit https://git-scm.com/
49
-
* Node.js: You need to have Node.js installed. You can check this in the console with `node -v`. For installation instructions visit https://nodejs.org/en/
50
-
* Npm: You need to have npm installed. You can check this in the console with `npm -v`. For installation instructions head to https://www.npmjs.com/get-npm
78
+
Before starting the installation you need to make sure you have a recent version of [Git](https://git-scm.com/), [Nodejs](https://nodejs.org/en/) and [Npm](https://www.npmjs.com/get-npm) installed.
79
+
E.g. we have the following versions:
80
+
```
81
+
$ git --version
82
+
git version 2.14.2.windows.1
83
+
$ node --version
84
+
v10.15.0
85
+
$ npm --version
86
+
4.6.0
87
+
88
+
Git: 2.14.2
89
+
Node: 10.15.0
90
+
Npm: 4.6.0
91
+
OS: Windows 10
92
+
```
51
93
52
-
**INSTALLATION**
94
+
**DOCKER INSTALLATION**
95
+
96
+
The Clock of Change API server comes bundled as a Docker Container, which enables you to run then server out of the box.
97
+
98
+
Of course you need to have a recent version of [Docker](https://www.docker.com/get-started) installed. If you don't have Docker, follow the instructions of the link.
99
+
You can check the version like this:
100
+
```
101
+
$ docker -v
102
+
Docker version 18.09.1, build 4c52b90
103
+
```
104
+
105
+
To run the Docker version, follow these steps:
106
+
1. First you need to clone the git repository of the Clock of Change API. Head to a directory where you want the git repository to reside
107
+
and open the directory in the console. Then run `git clone https://github.com/Human-Connection/Clock-of-Change-API.git` to clone the repository to this directory.
108
+
2. Go to the newly created Clock-of-Change-API directory (`cd Clock-of-Change-API` in the console)
109
+
3. Run `docker-compose up`. This will build the Docker container on first startup and run it. This can take a while, but after some time you should see the Clock of Change ticking.
110
+
111
+
Now the Clock of Change API server is ready for usage at [http://127.0.0.1:1337](http://127.0.0.1:1337)
112
+
113
+
**LOCAL INSTALLATION & USAGE**
114
+
115
+
If you do not want to use the docker version, you can also install the Clock of Change API server locally.
53
116
54
117
1. First you need to clone the git repository of the Clock of Change API. Head to a directory where you want the git repository to reside
55
118
and open the directory in the console. Then run `git clone https://github.com/Human-Connection/Clock-of-Change-API.git` to clone the repository to this directory.
@@ -65,13 +128,31 @@ Now the Clock of Change API server is ready to tick.
65
128
66
129
**START THE SERVER**
67
130
131
+
This section only applies if you have chosen the local installation.
132
+
When installing the Clock of Change API server with Docker, the server is starting automatically.
133
+
68
134
In the base Clock-of-Change-API directory run
69
135
70
136
`npm run start`
71
137
72
138
in the console to start the Clock of Change API server.
73
139
This will start Nodemon and the Node.js server, which will start listening for and processing requests at [http://localhost:1337](http://localhost:1337).
74
140
141
+
**RUN DATABASE MIGRATIONS**
142
+
143
+
This section only applies if you have chosen the local installation.
144
+
When installing the Clock of Change API server with Docker, the database migrations are applied automatically.
145
+
146
+
To create the necessary tables by applying the database migrations, run `db-migrate up` in the console.
147
+
148
+
This should give you an output like this:
149
+
```
150
+
$ db-migrate up
151
+
[INFO] Processed migration 20190206134449-entries
152
+
[INFO] Processed migration 20190206140226-apikeys
153
+
[INFO] Done
154
+
```
155
+
75
156
**MAKE REQUESTS**
76
157
77
158
Pro Tip: Get [Postman](https://www.getpostman.com/) to make requests. This amazing tool makes working with APIs way easier.
0 commit comments