Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.

Commit cac450d

Browse files
pantselPanagis Tselentis
authored andcommitted
Use .env instead of local.js and update README.md
1 parent 031aa05 commit cac450d

File tree

7 files changed

+67
-65
lines changed

7 files changed

+67
-65
lines changed

.env_example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
PORT=1337
2+
NODE_ENV=production
3+
KONGA_HOOK_TIMEOUT=120000
4+
DB_ADAPTER=postgres
5+
DB_URI=postgresql://localhost:5432/konga
6+
KONGA_LOG_LEVEL=warn
7+
TOKEN_SECRET=some_secret_token

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,5 @@ nbproject
122122
/www/
123123
/kongadata/
124124
/certs/
125+
/.env
126+
.env

README.md

Lines changed: 49 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ _Konga is not an official app. No affiliation with [Kong](https://www.konghq.com
2020
- [**Used libraries**](#used-libraries)
2121
- [**Installation**](#installation)
2222
- [**Configuration**](#configuration)
23+
- [**Environment variables**](#environment-variables)
2324
- [**Running Konga**](#running-konga)
2425
- [**Upgrading**](#upgrading)
2526
- [**FAQ**](#faq)
@@ -51,23 +52,22 @@ It also works with Kong 0.13.* yet without the ability to manage services and ro
5152

5253
## Prerequisites
5354
- A running [Kong installation](https://getkong.org/)
54-
- Nodejs >= 8.11.3
55+
- Nodejs >= 8 (8.11.3 LTS is recommended)
5556
- Npm
5657

5758
## Used libraries
5859
* Sails.js, http://sailsjs.org/
5960
* AngularJS, https://angularjs.org/
60-
* Bootstrap, http://getbootstrap.com/
6161

6262
## Installation
6363

6464
Install `npm` and `node.js`. Instructions can be found [here](http://sailsjs.org/#/getStarted?q=what-os-do-i-need).
6565

66-
Install `bower`, `gulp` and `sails` packages.
66+
Install `bower`, ad `gulp` packages.
6767
```
6868
$ git clone https://github.com/pantsel/konga.git
6969
$ cd konga
70-
$ npm install
70+
$ npm i
7171
```
7272

7373
## Configuration
@@ -77,11 +77,33 @@ settings.
7777
There is an example configuration file on following path.
7878

7979
```
80-
config/local_example.js
80+
.env_example
8181
```
8282

83-
Just copy this to `config/local.js` and make necessary changes to it. Note that this
84-
`local.js` file is in .gitignore so it won't go to VCS at any point.
83+
Just copy this to `.env` and make necessary changes to it. Note that this
84+
`.env` file is in .gitignore so it won't go to VCS at any point.
85+
86+
## Environment variables
87+
These are the general environment variables Konga uses.
88+
89+
| VAR | DESCRIPTION | VALUES | DEFAULT |
90+
|--------------------|----------------------------------------------------------------------------------------------------------------------------|----------------------------------------|----------------------------------------------|
91+
| PORT | The port that will be used by Konga's server | - | 1337 |
92+
| NODE_ENV | The environment | `production`,`development` | `development` |
93+
| SSL_KEY_PATH | If you want to use SSL, this will be the absolute path to the .key file. Both `SSL_KEY_PATH` & `SSL_CRT_PATH` must be set. | - | null |
94+
| SSL_CRT_PATH | If you want to use SSL, this will be the absolute path to the .crt file. Both `SSL_KEY_PATH` & `SSL_CRT_PATH` must be set. | - | null |
95+
| KONGA_HOOK_TIMEOUT | The time in ms that Konga will wait for startup tasks to finish before exiting the process. | - | 60000 |
96+
| DB_ADAPTER | The database that Konga will use. If not set, the localDisk db will be used. | `mongo`,`mysql`,`postgres`,`sqlserver` | - |
97+
| DB_URI | The full db connection string. Depends on `DB_ADAPTER`. If this is set, no other DB related var is needed. | - | - |
98+
| DB_HOST | If `DB_URI` is not specified, this is the database host. Depends on `DB_ADAPTER`. | - | localhost |
99+
| DB_PORT | If `DB_URI` is not specified, this is the database port. Depends on `DB_ADAPTER`. | - | DB default. |
100+
| DB_USER | If `DB_URI` is not specified, this is the database user. Depends on `DB_ADAPTER`. | - | - |
101+
| DB_PASSWORD | If `DB_URI` is not specified, this is the database user's password. Depends on `DB_ADAPTER`. | - | - |
102+
| DB_DATABASE | If `DB_URI` is not specified, this is the name of Konga's db. Depends on `DB_ADAPTER`. | - | `konga_database` |
103+
| DB_PG_SCHEMA | If using postgres as a database, this is the schema that will be used. | - | `public` |
104+
| KONGA_LOG_LEVEL | The logging level | `silly`,`debug`,`info`,`warn`,`error` | `debug` on dev environment & `warn` on prod. |
105+
| TOKEN_SECRET | The secret that will be used to sign JWT tokens issued by Konga | - | - |
106+
85107

86108
### Databases Integration
87109

@@ -94,45 +116,42 @@ The application also supports some of the most popular databases out of the box:
94116
1. MySQL
95117
2. MongoDB
96118
3. PostgresSQL
97-
4. SQL Server
98119

99-
In order to use them, in your `/config/local.js` replace
100-
```
101-
models: {
102-
connection: process.env.DB_ADAPTER || 'localDiskDb',
103-
}
104-
```
105-
with
120+
In order to use them, set the appropriate env vars in your `.env` file.
121+
122+
123+
## Running Konga
124+
125+
### Development
106126
```
107-
models: {
108-
connection: process.env.DB_ADAPTER || 'the-name-of-adapter-you-wish-to-use', // 'mysql', 'mongo', 'sqlserver' or 'postgres'
109-
}
127+
$ npm start
110128
```
129+
Konga GUI will be available at `http://localhost:1337`
111130

112-
See [Sails adapters](http://sailsjs.com/documentation/concepts/extending-sails/adapters/available-adapters) for further configuration
131+
### Production
113132

114133
*****************************************************************************************
115-
##### Note :
116-
In case of `MySQL`, `PostgresSQL` or `SQL Server` adapters,
117-
you will need to prepare the database as explained on the next topic.
134+
In case of `MySQL` or `PostgresSQL` adapters, Konga will not perform db migrations when running in production mode.
118135

119-
*****************************************************************************************
136+
You can manually perform the migrations by calling ```$ node ./bin/konga.js prepare```
137+
, passing the args needed for the database connectivity.
120138

121-
## Running Konga
139+
For example:
122140

123-
### Development
124141
```
125-
$ npm start
142+
$ node ./bin/konga.js prepare --adapter postgres --uri postgresql://localhost:5432/konga
126143
```
127-
Konga GUI will be available at `http://localhost:1337`
144+
The process will exit after all migrations are completed.
128145

129-
### Production
146+
*****************************************************************************************
130147

148+
Finally:
131149
```
132150
$ npm run production
133151
```
134152
Konga GUI will be available at `http://localhost:1337`
135153

154+
136155
### Production Docker Image
137156

138157
The following instructions assume that you have a running Kong instance following the
@@ -152,20 +171,7 @@ $ docker run -p 1337:1337 \
152171
1. ##### Prepare the database
153172
> **Note**: You can skip this step if using the `mongo` adapter.
154173
155-
Konga will not perform db migrations when running in production mode.
156-
157-
You can manually perform the migrations by calling ```$ node ./bin/konga.js prepare```
158-
, passing the args needed for the database connectivity.
159-
160-
The available adapters are ```'postgres', or 'mysql'```
161-
162-
```
163-
$ node ./bin/konga.js prepare --adapter {adapter_name} --uri {full_connection_string}
164-
```
165-
The process will exit after all migrations are completed.
166-
167-
If you're deploying Konga via the docker image, you can prepare the database using
168-
an ephemeral container running the prepare command.
174+
You can prepare the database using an ephemeral container that runs the prepare command.
169175

170176
**Args**
171177

@@ -174,10 +180,9 @@ argument | description | default
174180
-c | command | -
175181
-a | adapter (can be `postgres` or `mysql`) | -
176182
-u | full database connection url | -
177-
-p | port | `1339`
178183

179184
```
180-
$ docker run --rm pantsel/konga:next -c prepare -a {{adapter}} -u {{connection-uri}} -p {{port}}
185+
$ docker run --rm pantsel/konga:next -c prepare -a {{adapter}} -u {{connection-uri}}
181186
```
182187

183188

@@ -224,26 +229,7 @@ This user data is populated to the database if there is not already any user dat
224229

225230
You may also configure Konga to authenticate via [LDAP](./docs/LDAP.md).
226231

227-
## Environment variables
228-
These are the general environment variables Konga uses.
229232

230-
| VAR | DESCRIPTION | VALUES | DEFAULT |
231-
|--------------------|----------------------------------------------------------------------------------------------------------------------------|----------------------------------------|----------------------------------------------|
232-
| PORT | The port that will be used by Konga's server | - | 1337 |
233-
| NODE_ENV | The environment | `production`,`development` | `development` |
234-
| SSL_KEY_PATH | If you want to use SSL, this will be the absolute path to the .key file. Both `SSL_KEY_PATH` & `SSL_CRT_PATH` must be set. | - | null |
235-
| SSL_CRT_PATH | If you want to use SSL, this will be the absolute path to the .crt file. Both `SSL_KEY_PATH` & `SSL_CRT_PATH` must be set. | - | null |
236-
| KONGA_HOOK_TIMEOUT | The time in ms that Konga will wait for startup tasks to finish before exiting the process. | - | 60000 |
237-
| DB_ADAPTER | The database that Konga will use. If not set, the localDisk db will be used. | `mongo`,`mysql`,`postgres`,`sqlserver` | - |
238-
| DB_URI | The full db connection string. Depends on `DB_ADAPTER`. If this is set, no other DB related var is needed. | - | - |
239-
| DB_HOST | If `DB_URI` is not specified, this is the database host. Depends on `DB_ADAPTER`. | - | localhost |
240-
| DB_PORT | If `DB_URI` is not specified, this is the database port. Depends on `DB_ADAPTER`. | - | DB default. |
241-
| DB_USER | If `DB_URI` is not specified, this is the database user. Depends on `DB_ADAPTER`. | - | - |
242-
| DB_PASSWORD | If `DB_URI` is not specified, this is the database user's password. Depends on `DB_ADAPTER`. | - | - |
243-
| DB_DATABASE | If `DB_URI` is not specified, this is the name of Konga's db. Depends on `DB_ADAPTER`. | - | `konga_database` |
244-
| DB_PG_SCHEMA | If using postgres as a database, this is the schema that will be used. | - | `public` |
245-
| KONGA_LOG_LEVEL | The logging level | `silly`,`debug`,`info`,`warn`,`error` | `debug` on dev environment & `warn` on prod. |
246-
| TOKEN_SECRET | The secret that will be used to sign JWT tokens issued by Konga | - | - |
247233
## Upgrading
248234
In some cases a newer version of Konga may introduce new db tables, collections or changes in schemas.
249235
The only thing you need to do is to start Konga in dev mode once so that the migrations will be applied.

app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* The same command-line arguments are supported, e.g.:
2020
* `node app.js --silent --port=80 --prod`
2121
*/
22-
22+
require('dotenv').config()
2323

2424
// Ensure a "sails" can be located:
2525
let sails;

bin/konga.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node bin
2+
require('dotenv').config()
23
var argv = require('minimist')(process.argv.slice(2));
34
var child_process = require('child_process');
45
var spawn = child_process.spawn

package-lock.json

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"bcryptjs": "2.3.0",
1616
"bluebird": "3.0.5",
1717
"bower": "^1.8.4",
18+
"dotenv": "^6.0.0",
1819
"ejs": "^2.6.1",
1920
"grunt": "^1.0.3",
2021
"grunt-contrib-clean": "^1.1.0",

0 commit comments

Comments
 (0)