-
Notifications
You must be signed in to change notification settings - Fork 911
/
Copy pathenv.ts
75 lines (72 loc) · 2.69 KB
/
env.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
import * as dotenv from 'dotenv';
import * as path from 'path';
import * as pkg from '../package.json';
import {
getOsEnv, getOsEnvOptional, getOsPath, getOsPaths, normalizePort, toBool, toNumber
} from './lib/env';
/**
* Load .env file or for tests the .env.test file.
*/
dotenv.config({ path: path.join(process.cwd(), `.env${((process.env.NODE_ENV === 'test') ? '.test' : '')}`) });
/**
* Environment variables
*/
export const env = {
node: process.env.NODE_ENV || 'development',
isProduction: process.env.NODE_ENV === 'production',
isTest: process.env.NODE_ENV === 'test',
isDevelopment: process.env.NODE_ENV === 'development',
app: {
name: getOsEnv('APP_NAME'),
version: (pkg as any).version,
description: (pkg as any).description,
host: getOsEnv('APP_HOST'),
schema: getOsEnv('APP_SCHEMA'),
routePrefix: getOsEnv('APP_ROUTE_PREFIX'),
port: normalizePort(process.env.PORT || getOsEnv('APP_PORT')),
banner: toBool(getOsEnv('APP_BANNER')),
dirs: {
migrations: getOsPaths('TYPEORM_MIGRATIONS'),
migrationsDir: getOsPath('TYPEORM_MIGRATIONS_DIR'),
entities: getOsPaths('TYPEORM_ENTITIES'),
entitiesDir: getOsPath('TYPEORM_ENTITIES_DIR'),
controllers: getOsPaths('CONTROLLERS'),
middlewares: getOsPaths('MIDDLEWARES'),
interceptors: getOsPaths('INTERCEPTORS'),
subscribers: getOsPaths('SUBSCRIBERS'),
resolvers: getOsPaths('RESOLVERS'),
},
},
log: {
level: getOsEnv('LOG_LEVEL'),
json: toBool(getOsEnvOptional('LOG_JSON')),
output: getOsEnv('LOG_OUTPUT'),
},
db: {
type: getOsEnv('TYPEORM_CONNECTION'),
host: getOsEnvOptional('TYPEORM_HOST'),
port: toNumber(getOsEnvOptional('TYPEORM_PORT')),
username: getOsEnvOptional('TYPEORM_USERNAME'),
password: getOsEnvOptional('TYPEORM_PASSWORD'),
database: getOsEnv('TYPEORM_DATABASE'),
synchronize: toBool(getOsEnvOptional('TYPEORM_SYNCHRONIZE')),
logging: getOsEnv('TYPEORM_LOGGING'),
},
graphql: {
enabled: toBool(getOsEnv('GRAPHQL_ENABLED')),
route: getOsEnv('GRAPHQL_ROUTE'),
editor: toBool(getOsEnv('GRAPHQL_EDITOR')),
},
swagger: {
enabled: toBool(getOsEnv('SWAGGER_ENABLED')),
route: getOsEnv('SWAGGER_ROUTE'),
username: getOsEnv('SWAGGER_USERNAME'),
password: getOsEnv('SWAGGER_PASSWORD'),
},
monitor: {
enabled: toBool(getOsEnv('MONITOR_ENABLED')),
route: getOsEnv('MONITOR_ROUTE'),
username: getOsEnv('MONITOR_USERNAME'),
password: getOsEnv('MONITOR_PASSWORD'),
},
};