1 |
|
2 |
|
3 | import type { Config } from './types'
|
4 |
|
5 | export const createConfig = (defaults: Object = {}): Config => ({
|
6 | mainframe_url:
|
7 | process.env.MAINFRAME_URL ||
|
8 | defaults.mainframe_url ||
|
9 | 'https://api.mainframe.com/bots/v1',
|
10 | secret: process.env.MAINFRAME_SECRET || '',
|
11 | server_port: process.env.PORT
|
12 | ? parseInt(process.env.PORT, 10)
|
13 | : defaults.server_port || 4000,
|
14 | server_url: process.env.SERVER_URL || defaults.server_url,
|
15 | username: process.env.USERNAME || defaults.username,
|
16 | })
|
17 |
|
18 | export const validateConfig = (config: Config) => {
|
19 | if (!config.secret) {
|
20 | throw new Error('Missing secret')
|
21 | }
|
22 | if (!config.server_url) {
|
23 | throw new Error('Missing server URL')
|
24 | }
|
25 | if (!config.username) {
|
26 | throw new Error('Missing username')
|
27 | }
|
28 | }
|