diff --git a/config/default.json5 b/config/default.json5 index 6778151c..f45eb45d 100644 --- a/config/default.json5 +++ b/config/default.json5 @@ -6,9 +6,11 @@ filter: null, path: null }, - - // Specifies if configuration using Conf() should be persisted between restarts - persistConf: true, + conf: { + name: 'config', + // Specifies if configuration using Conf() should be persisted between restarts + persist: true + }, // Settings for blockchain related function blockchain: { diff --git a/config/development.json5 b/config/development.json5 index 6b99a8f6..b33ae80e 100644 --- a/config/development.json5 +++ b/config/development.json5 @@ -1,7 +1,10 @@ { host: "localhost", port: 3030, - persistConf: false, + conf: { + name: 'dev-config', + persist: true + }, db: { dialect: "postgres", host: "localhost", diff --git a/src/app.ts b/src/app.ts index e3834494..909d6b42 100644 --- a/src/app.ts +++ b/src/app.ts @@ -13,7 +13,7 @@ import services from './services' import appHooks from './app.hooks' import sequelize from './sequelize' import blockchain from './blockchain/' -import conf from './conf' +import { configure as confConfigure } from './conf' // Don't remove this comment. It's needed to format import lines nicely. const app: Application = express(feathers()) @@ -30,7 +30,7 @@ app.configure(express.rest()) app.configure(socketio()) app.configure(sequelize) -app.configure(conf) +app.configure(confConfigure) // Configure other middleware (see `middleware/index.js`) app.configure(middleware) diff --git a/src/blockchain/events.ts b/src/blockchain/events.ts index af80af18..ad59e5ff 100644 --- a/src/blockchain/events.ts +++ b/src/blockchain/events.ts @@ -1,7 +1,7 @@ import { Contract, EventData } from 'web3-eth-contract' import { BlockHeader, Eth } from 'web3-eth' import { Subscription } from 'web3-core-subscriptions' -import Conf from 'conf' +import confFactory from '../conf' import config from 'config' import { EventEmitter } from 'events' import { NotImplemented } from '@feathersjs/errors' @@ -177,11 +177,11 @@ abstract class BaseEventsEmitter extends AutoStartStopEventEmitter { if (options.blockTracker instanceof BlockTracker) { this.blockTracker = options.blockTracker } else { - const confStore = options.blockTracker.store || new Conf() + const confStore = options.blockTracker.store || confFactory() this.blockTracker = new BlockTracker(confStore) } } else { - this.blockTracker = new BlockTracker(new Conf()) + this.blockTracker = new BlockTracker(confFactory()) } if (options?.newBlockEmitter) { diff --git a/src/conf.ts b/src/conf.ts index 1d0484f5..f0e0b91a 100644 --- a/src/conf.ts +++ b/src/conf.ts @@ -1,13 +1,44 @@ import { Application } from './declarations' import config from 'config' import Conf from 'conf' -import { factory } from './logger' +import { factory as logFactory } from './logger' -const logger = factory('conf') +const logger = logFactory('conf') -export default function conf (app: Application): void { - if (!config.get('persistConf')) { +export interface ConfOptions { + host: string + port: number + log?: { + level?: string + filter?: string + path?: string + } + blockchain: { + provider: string + pinningContractAddress: string + startingBlock: string | number + eventsEmitter?: { + polling: boolean + pollingInterval?: number + confirmations?: number + } + } + newBlockEmitter: { + polling: boolean + pollingInterval?: number + } +} + +export default function factory (): Conf { + const configName = config.get('conf.name') + + return new Conf({ configName }) +} + +export function configure (app: Application): void { + if (!config.get('conf.persist')) { logger.info('Clearing all persisted configuration.') - new Conf().clear() + + factory().clear() } }