Skip to content

Commit

Permalink
refactor: add api host to config
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadtirmazi committed Aug 2, 2023
1 parent f43b552 commit fec523d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"packageManager": "[email protected]",
"main": "build/index.js",
"types": "build/index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/Alien-Worlds/aw-history"
},
"files": [
"build"
],
Expand Down Expand Up @@ -42,4 +46,4 @@
"crypto": "^1.0.1",
"ts-node": "^10.9.1"
}
}
}
1 change: 1 addition & 0 deletions src/api/api.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const apiCommand = new Command();

apiCommand
.version('1.0', '-v, --version')
.option('-h, --host <host>')
.option('-p, --port <port>')
.parse(process.argv);
2 changes: 2 additions & 0 deletions src/api/api.types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { UnknownObject } from '@alien-worlds/aw-core';

export type ApiCommandOptions = {
host: string;
port: number;
};

export type ApiConfig<DatabaseConfig = UnknownObject> = {
host: string;
port: number;
database: DatabaseConfig;
};
32 changes: 13 additions & 19 deletions src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import { Api } from './../api/api';
import { FilterCommandOptions, FilterConfig } from '../filter';
import { buildBroadcastConfig } from '@alien-worlds/aw-broadcast';
import { BlockReaderConfig, ConfigVars, parseToBigInt, UnknownObject } from '@alien-worlds/aw-core';
import { WorkersConfig } from '@alien-worlds/aw-workers';

import { ApiCommandOptions, ApiConfig } from '../api';
import { BlockchainConfig, BootstrapCommandOptions, BootstrapConfig } from '../bootstrap';
import { ReaderCommandOptions, ReaderConfig } from '../reader';
import { AbisConfig, AbisServiceConfig, BlockRangeScanConfig, FeaturedConfig, FeaturedContractDataCriteria, ProcessorTaskQueueConfig, UnprocessedBlockQueueConfig } from '../common';
import { FilterCommandOptions, FilterConfig } from '../filter';
import { ProcessorCommandOptions, ProcessorConfig } from '../processor';
import { ReaderCommandOptions, ReaderConfig } from '../reader';
import { Api } from './../api/api';
import { HistoryToolsConfig } from './config.types';
import { BlockReaderConfig, ConfigVars, UnknownObject, parseToBigInt } from '@alien-worlds/aw-core';
import {
AbisConfig,
AbisServiceConfig,
BlockRangeScanConfig,
FeaturedConfig,
FeaturedContractDataCriteria,
ProcessorTaskQueueConfig,
UnprocessedBlockQueueConfig,
} from '../common';
import { WorkersConfig } from '@alien-worlds/aw-workers';
import { buildBroadcastConfig } from '@alien-worlds/aw-broadcast';

export * from './config.types';

Expand Down Expand Up @@ -105,6 +98,7 @@ export const buildApiConfig = (
databaseConfigBuilder: (vars: ConfigVars, ...args: unknown[]) => UnknownObject,
options?: ApiCommandOptions
): ApiConfig => ({
host: vars.getStringEnv('API_HOST') || options.host || 'localhost',
port: vars.getNumberEnv('API_PORT') || options.port || 8080,
database: databaseConfigBuilder(vars),
});
Expand All @@ -122,13 +116,13 @@ export const buildBootstrapConfig = (
startBlock: options?.startBlock
? parseToBigInt(options?.startBlock)
: vars.getStringEnv('START_BLOCK')
? parseToBigInt(vars.getStringEnv('START_BLOCK'))
: null,
? parseToBigInt(vars.getStringEnv('START_BLOCK'))
: null,
endBlock: options?.endBlock
? parseToBigInt(options?.endBlock)
: vars.getStringEnv('END_BLOCK')
? parseToBigInt(vars.getStringEnv('END_BLOCK'))
: null,
? parseToBigInt(vars.getStringEnv('END_BLOCK'))
: null,
startFromHead: vars.getBooleanEnv('START_FROM_HEAD') || false,
mode: options?.mode || vars.getStringEnv('MODE') || 'default',
abis: buildAbisServiceConfig(vars),
Expand Down

0 comments on commit fec523d

Please sign in to comment.