-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconfig.ts
108 lines (92 loc) · 2.92 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import appRootDir from 'app-root-path'
import dotenv from 'dotenv'
import { strict as assert } from 'assert'
import { Oas3ToolsObjectOrientedConfig } from '@jolocom/oas3-tools-object-oriented'
import { oas3AppOptions } from './swagger'
// Defining default environment variables
process.env.NODE_ENV = process.env.APP_ENV || 'dev';
process.env.API_VERSION = process.env.API_VERSION || 'v1';
// Loading env variables defined in .env file into the process.env scope
const envFound = dotenv.config()
if (envFound.error) {
throw new Error('Couldn\'t find .env file')
}
// Asserting that required env variables are defined
const assertRequiredVariablesDefined = () => {
assert(process.env.APP_PORT, "Expected 'process.env.APP_PORT' to be defined")
assert(process.env.APP_ENV, "Expected 'process.env.APP_ENV' to be defined")
assert(process.env.APP_HOST, "Expected 'process.env.APP_HOST' to be defined")
assert(process.env.APP_SCHEME, "Expected 'process.env.APP_SCHEME' to be defined")
assert(process.env.SDK_CALLBACK_URL, "Expected 'process.env.SDK_CALLBACK_URL' to be defined")
}
assertRequiredVariablesDefined()
/**
* The main application configuration definition abstraction.
*/
export interface AppConfig {
port: string,
env: string,
host: string,
schema: string,
apiVersion: string,
apiRootPath: string,
controllersPath: string,
fixturesPath: string,
sdk: {
passwordFilePath: string,
callbackUrl: string,
},
db: {
type: string,
database: string,
logging: string[],
entities: string[],
migrations: string[],
migrationsRun: boolean,
synchronize: boolean,
cli: {
migrationsDir: string,
},
},
logger: {
logDir: string,
},
swagger: Oas3ToolsObjectOrientedConfig
}
const oas3DeclarationFilePath = appRootDir + '/src/api/openapi.yaml'
/**
* The main application configuration definition.
*/
export const config: AppConfig = {
port: process.env.APP_PORT as string,
env: process.env.APP_ENV as string,
host: process.env.APP_HOST as string,
schema: process.env.APP_SCHEME as string,
apiVersion: process.env.API_VERSION as string,
apiRootPath: '/api/' + process.env.API_VERSION,
controllersPath: appRootDir + '/src/controller',
fixturesPath: appRootDir + '/fixtures',
sdk: {
passwordFilePath: process.env.SDK_PASSWORD_FILE_PATH || appRootDir + '/var/password.txt',
callbackUrl: process.env.SDK_CALLBACK_URL as string,
},
db: {
type: 'sqlite',
database: appRootDir + '/var/db.sqlite3',
logging: ['error', 'warn', 'schema'],
entities: [...require('@jolocom/sdk-storage-typeorm').entityList],
migrations: [appRootDir + '/migration/*.ts'],
migrationsRun: true,
synchronize: true,
cli: {
migrationsDir: appRootDir + '/migration',
},
},
logger: {
logDir: process.env.LOG_DIR || appRootDir + '/var/log',
},
swagger: {
oas3AppOptions: oas3AppOptions(oas3DeclarationFilePath),
oas3DeclarationFilePath,
}
}