@@ -2,6 +2,7 @@ import { Server, createServer } from 'http';
2
2
import { Socket } from 'net' ;
3
3
import * as express from 'express' ;
4
4
import * as expressWinston from 'express-winston' ;
5
+ import * as winston from 'winston' ;
5
6
import { v4 as uuid } from 'uuid' ;
6
7
import * as cors from 'cors' ;
7
8
import { addAsync , ExpressWithAsync } from '@awaitjs/express' ;
@@ -50,19 +51,20 @@ export interface ApiServer {
50
51
terminate : ( ) => Promise < void > ;
51
52
}
52
53
53
- export async function startApiServer ( {
54
- datastore,
55
- chainId,
56
- httpLogLevel,
57
- } : {
54
+ export async function startApiServer ( opts : {
58
55
datastore : DataStore ;
59
56
chainId : ChainID ;
57
+ /** If not specified, this is read from the STACKS_BLOCKCHAIN_API_HOST env var. */
58
+ serverHost ?: string ;
59
+ /** If not specified, this is read from the STACKS_BLOCKCHAIN_API_PORT env var. */
60
+ serverPort ?: number ;
60
61
httpLogLevel ?: LogLevel ;
61
62
} ) : Promise < ApiServer > {
62
- const app = addAsync ( express ( ) ) ;
63
+ const { datastore , chainId , serverHost , serverPort , httpLogLevel } = opts ;
63
64
64
- const apiHost = process . env [ 'STACKS_BLOCKCHAIN_API_HOST' ] ;
65
- const apiPort = parseInt ( process . env [ 'STACKS_BLOCKCHAIN_API_PORT' ] ?? '' ) ;
65
+ const app = addAsync ( express ( ) ) ;
66
+ const apiHost = serverHost ?? process . env [ 'STACKS_BLOCKCHAIN_API_HOST' ] ;
67
+ const apiPort = serverPort ?? parseInt ( process . env [ 'STACKS_BLOCKCHAIN_API_PORT' ] ?? '' ) ;
66
68
67
69
if ( ! apiHost ) {
68
70
throw new Error (
@@ -214,7 +216,7 @@ export async function startApiServer({
214
216
215
217
app . use (
216
218
expressWinston . errorLogger ( {
217
- winstonInstance : logger ,
219
+ winstonInstance : logger as winston . Logger ,
218
220
metaField : ( null as unknown ) as string ,
219
221
blacklistedMetaFields : [ 'trace' , 'os' , 'process' ] ,
220
222
} )
0 commit comments