Skip to content

Commit d1e49fb

Browse files
author
hirsch88
committed
add env config
1 parent 92b897b commit d1e49fb

28 files changed

+142
-318
lines changed

.env.example

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
APP_NAME=qt-api
2+
APP_ENV=local
3+
APP_HOST=http://localhost
4+
APP_PORT=3000
5+
6+
DEBUG=app*,api*,core*
7+
LOG_LEVEL=debug
8+
LOG_ADAPTER=debug
9+
10+
DB_CLIENT=pg
11+
DB_CONNECTION=postgres://root:root@localhost:5432/my_database
12+
DB_POOL_MIN=0
13+
DB_POOL_MAX=7
14+
DB_MIGRATION_DIR=./src/database/migrations
15+
DB_MIGRATION_TABLE=version
16+
DB_SEEDS_DIR=./src/database/seeds
17+
18+
19+
AUTH0_HOST=https://w3tecch.auth0.com
20+
AUTH0_OAUTH=/oauth
21+
AUTH0_API=/api/v2
22+
AUTH0_CLIENT_ID=auth0_client_id
23+
AUTH0_CLIENT_SECRET=auth0_client_secret
24+
AUTH0_AUDIENCE=https://my.auth0.com/api/v2/
25+
AUTH0_GRANT_TYPE=client_credentials

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ node_modules/
1010
bower_components/
1111
npm-debug.log
1212
yarn-error.log
13+
.env
1314

1415
# OS generated files #
1516
.DS_Store

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ The port will be displayed to you as `http://0.0.0.0:3000` (or if you prefer IPv
5050
* Run `npm run build` to generated all JavaScript files from your TypeScript sources. After this step you can deploy the app on any server.
5151
* There is also a vscode task for this called build.
5252
* To start the builded app use `npm start`.
53-
* With `npm run zip` it will generate the JavaScript source and pack them into to a deployable zip file into the dist folder.
5453

5554
### Docs
5655
* Run `npm run docs` to generate all doc files and serve it on `http://0.0.0.0:8080`

build/tasks/zip.js

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

knexfile.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import * as _ from 'lodash';
2-
3-
const config = require('./src/config');
4-
5-
let databaseConfig = {};
6-
7-
_.forOwn(_.clone(config), (value, key) => databaseConfig[`${key}`] = value.database);
8-
9-
module.exports = databaseConfig;
1+
require('dotenv').config();
2+
3+
module.exports = {
4+
client: process.env.DB_CLIENT,
5+
connection: process.env.DB_CONNECTION,
6+
migrations: {
7+
directory: process.env.DB_MIGRATION_DIR,
8+
tableName: process.env.DB_MIGRATION_TABLE
9+
},
10+
seeds: {
11+
directory: process.env.DB_SEEDS_DIR
12+
}
13+
};

package.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@
5757
"@types/bookshelf": "^0.8.38",
5858
"@types/cors": "^2.8.1",
5959
"@types/debug": "0.0.29",
60+
"@types/dotenv": "^4.0.0",
6061
"@types/express": "^4.0.35",
6162
"@types/faker": "^4.1.0",
6263
"@types/helmet": "0.0.34",
6364
"@types/inversify": "^2.0.33",
6465
"@types/inversify-express-utils": "^2.0.0",
66+
"@types/jest": "^19.2.2",
6567
"@types/knex": "0.0.47",
6668
"@types/lodash": "^4.14.63",
6769
"@types/morgan": "^1.7.32",
@@ -75,22 +77,9 @@
7577
"compression": "^1.6.2",
7678
"cors": "^2.8.1",
7779
"debug": "^2.6.0",
80+
"dotenv": "^4.0.0",
7881
"express": "^4.14.0",
7982
"faker": "^3.1.0",
80-
"helmet": "^3.4.0",
81-
"inversify": "^4.1.0",
82-
"inversify-express-utils": "^3.5.1",
83-
"knex": "^0.12.7",
84-
"lodash": "^4.17.4",
85-
"morgan": "^1.7.0",
86-
"pg": "^6.1.5",
87-
"reflect-metadata": "^0.1.10",
88-
"request": "^2.81.0",
89-
"serve-favicon": "^2.4.2",
90-
"ts-node": "^2.0.0",
91-
"typescript": "^2.3.2",
92-
"winston": "^2.3.1",
93-
"@types/jest": "^19.2.2",
9483
"gulp": "^3.9.1",
9584
"gulp-clean": "^0.3.2",
9685
"gulp-concat": "^2.6.1",
@@ -106,20 +95,31 @@
10695
"gulp-typedoc": "^2.0.2",
10796
"gulp-typescript": "^3.1.4",
10897
"gulp-zip": "^3.2.0",
98+
"helmet": "^3.4.0",
10999
"http-server": "^0.9.0",
100+
"inversify": "^4.1.0",
101+
"inversify-express-utils": "^3.5.1",
110102
"jasmine-spec-reporter": "^4.0.0",
111103
"jest": "^19.0.2",
104+
"knex": "^0.12.7",
105+
"lodash": "^4.17.4",
106+
"morgan": "^1.7.0",
112107
"nodemon": "^1.11.0",
113108
"path": "^0.12.7",
109+
"pg": "^6.1.5",
110+
"reflect-metadata": "^0.1.10",
114111
"request": "^2.79.0",
115112
"require-dir": "^0.3.1",
116113
"run-sequence": "^1.2.2",
114+
"serve-favicon": "^2.4.2",
117115
"sqlite3": "^3.1.8",
118116
"ts-jest": "^19.0.11",
117+
"ts-node": "^2.0.0",
119118
"tslint": "^4.3.1",
120119
"typedoc": "^0.5.5",
121120
"typescript": "^2.2.1",
122-
"typings": "^2.1.0"
121+
"typings": "^2.1.0",
122+
"winston": "^2.3.1"
123123
},
124124
"jest": {
125125
"transform": {

src/api/models/User.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ export class User extends core.Bookshelf.Model<User> {
2020
public get LastName(): string { return this.get('lastName'); }
2121
public set LastName(value: string) { this.set({ id: value }); };
2222

23-
public get Username(): string { return this.get('username'); }
24-
public set Username(value: string) { this.set({ id: value }); };
25-
2623
public get Email(): string { return this.get('email'); }
2724
public set Email(value: string) { this.set({ id: value }); };
2825

src/config.ts

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

src/console/CleanDatabaseCommand.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require('dotenv').config();
2+
13
process.env.DEBUG = 'console*';
24

35
import * as Knex from 'knex';

src/core/Bootstrap.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const log = new Log('core:Bootstrap');
1212

1313
/**
1414
* This class helps us to create an express app very easy and moreover
15-
* to give us a better posibility to extend the bootstrap process
15+
* to give us a better possibility to extend the bootstrap process
1616
*
1717
* @export
1818
* @class Bootstrap
@@ -30,12 +30,11 @@ export class Bootstrap {
3030
*/
3131
static getApp(): express.Application {
3232
const app = express();
33-
const config = Environment.getConfig();
3433

3534
// Set serve configs for running it
36-
app.set('host', config.server.host);
37-
app.set('port', Bootstrap.normalizePort(config.server.port));
38-
log.debug('app is created');
35+
app.set('host', Environment.get('APP_HOST'));
36+
app.set('port', Bootstrap.normalizePort(Environment.get<string>('PORT') || Environment.get<string>('APP_PORT')));
37+
log.debug('app is defined');
3938
return app;
4039
}
4140

0 commit comments

Comments
 (0)