-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathschema.ts
162 lines (158 loc) · 3.86 KB
/
schema.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import convict from 'convict';
import yaml from 'js-yaml';
import json5 from 'json5';
convict.addParser([
{ extension: 'json', parse: JSON.parse },
{ extension: ['yaml', 'yml'], parse: yaml.safeLoad },
{ extension: ['json5'], parse: json5.parse },
]);
function logLevel(options) {
return {
doc: 'The level of logging to be recorded',
format: ['error', 'info', 'verbose', 'debug', 'silly'],
...options,
};
}
function logPath(options) {
return {
doc: 'Where the logs will be recorded to',
...options,
};
}
export const schema = convict({
env: {
env: 'NODE_ENV',
format: ['production', 'development', 'test'],
arg: 'env',
default: 'production',
},
ui: {
protocol: {
env: 'UI_PROTOCOL',
arg: 'ui-protocol',
format: ['http', 'https'],
default: 'http',
},
host: {
doc: 'The host used for hosting the frontend web app',
env: 'UI_HOST',
format: '*',
arg: 'ui-host',
default: 'localhost',
},
port: {
doc: 'The port number used for hosting the frontend web app',
env: 'UI_PORT',
format: 'port',
arg: 'ui-port',
default: 3000,
},
apiBaseUrl: {
default: null,
doc: 'The target API URL used by the web app to communicate with the server',
env: 'API_BASE_URL',
format: '*',
arg: 'ui-api-base-url',
},
},
server: {
log: {
/*
TODO: Rather than having a config for this we could probably allow have hooks
to add loggers straight into winston
*/
console: {
level: logLevel({
default: 'verbose',
env: 'CONSOLE_LOG_LEVEL',
arg: 'console-log-level',
}),
},
file: {
level: logLevel({
default: 'verbose',
env: 'FILE_LOG_LEVEL',
arg: 'file-log-level',
}),
path: {
default: './openapi-platform-server.log',
env: 'FILE_LOG_PATH',
arg: 'file-log-path',
},
},
error: {
path: logPath({
default: './openapi-platform-server.error.log',
env: 'ERROR_LOG_PATH',
arg: 'error-log-path',
}),
},
},
protocol: {
env: 'SERVER_PROTOCOL',
arg: 'server-protocol',
format: ['http', 'https'],
default: 'http',
},
host: {
doc: 'The accepted address for connects to the server',
default: 'localhost',
env: 'SERVER_HOST',
arg: 'server-host',
},
port: {
doc: 'The port number used for incoming connections.',
env: 'SERVER_PORT',
arg: 'server-port',
format: 'port',
default: 8080,
},
// TODO: You should be able to add this sort of stuff via some sort of hook
useCors: {
doc: 'Whether or not CORS requests should be allowed.',
env: 'USE_CORS',
arg: 'use-cors',
format: Boolean,
default: true,
},
},
database: {
name: {
doc: 'The name of the PostgreSQL database to connect to.',
env: 'DB_NAME',
arg: 'db-name',
format: String,
default: undefined,
},
host: {
doc: 'The hostname of the PostgreSQL database to connect to.',
env: 'DB_HOST',
arg: 'db-host',
format: '*',
default: 'localhost',
},
port: {
doc: 'The port of the PostgreSQL database to connect to.',
env: 'DB_PORT',
arg: 'db-port',
default: 5432,
format: 'port',
},
username: {
doc: 'The username of the PostgreSQL database to connect to.',
env: 'DATABASE_USERNAME',
arg: 'db-username',
format: String,
default: undefined,
sensitive: true,
},
password: {
doc: 'The password of the PostgreSQL database to connect to.',
env: 'DATABASE_PASSWORD',
arg: 'db-password',
format: String,
default: undefined,
sensitive: true,
},
},
});