2021-08-12 09:58:13 +00:00
|
|
|
//
|
|
|
|
// Copyright 2021 Vulcanize, Inc.
|
|
|
|
//
|
|
|
|
|
2021-07-02 10:56:32 +00:00
|
|
|
import fs from 'fs-extra';
|
|
|
|
import path from 'path';
|
|
|
|
import toml from 'toml';
|
|
|
|
import debug from 'debug';
|
|
|
|
import { ConnectionOptions } from 'typeorm';
|
|
|
|
|
|
|
|
import { Config as CacheConfig } from '@vulcanize/cache';
|
|
|
|
|
|
|
|
const log = debug('vulcanize:config');
|
|
|
|
|
|
|
|
export interface Config {
|
|
|
|
server: {
|
|
|
|
host: string;
|
|
|
|
port: number;
|
2021-07-28 04:34:07 +00:00
|
|
|
mode: string;
|
2021-07-02 10:56:32 +00:00
|
|
|
};
|
|
|
|
database: ConnectionOptions;
|
|
|
|
upstream: {
|
2021-07-09 07:08:25 +00:00
|
|
|
cache: CacheConfig,
|
2021-07-15 07:40:07 +00:00
|
|
|
ethServer: {
|
|
|
|
gqlApiEndpoint: string;
|
|
|
|
gqlPostgraphileEndpoint: string;
|
2021-07-28 04:34:07 +00:00
|
|
|
rpcProviderEndpoint: string
|
2021-07-15 07:40:07 +00:00
|
|
|
}
|
|
|
|
traceProviderEndpoint: string;
|
2021-07-06 11:25:11 +00:00
|
|
|
uniWatcher: {
|
|
|
|
gqlEndpoint: string;
|
|
|
|
gqlSubscriptionEndpoint: string;
|
|
|
|
};
|
|
|
|
tokenWatcher: {
|
|
|
|
gqlEndpoint: string;
|
|
|
|
gqlSubscriptionEndpoint: string;
|
|
|
|
}
|
2021-07-09 07:08:25 +00:00
|
|
|
},
|
2021-07-02 10:56:32 +00:00
|
|
|
jobQueue: {
|
|
|
|
dbConnectionString: string;
|
|
|
|
maxCompletionLag: number;
|
2021-08-04 13:12:59 +00:00
|
|
|
jobDelay?: number;
|
2021-07-02 10:56:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getConfig = async (configFile: string): Promise<Config> => {
|
|
|
|
const configFilePath = path.resolve(configFile);
|
|
|
|
const fileExists = await fs.pathExists(configFilePath);
|
|
|
|
if (!fileExists) {
|
|
|
|
throw new Error(`Config file not found: ${configFilePath}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const config = toml.parse(await fs.readFile(configFilePath, 'utf8'));
|
|
|
|
log('config', JSON.stringify(config, null, 2));
|
|
|
|
|
|
|
|
return config;
|
|
|
|
};
|