From 250a60edfa497966ca0e3405f7fb81e579c889ee Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Fri, 13 Sep 2024 09:40:18 +0530 Subject: [PATCH] Add a flag to enable ETH RPC server --- packages/util/src/config.ts | 3 +++ packages/util/src/server.ts | 29 ++++++++++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/util/src/config.ts b/packages/util/src/config.ts index b36fbade..9567a87a 100644 --- a/packages/util/src/config.ts +++ b/packages/util/src/config.ts @@ -252,6 +252,9 @@ export interface ServerConfig { // Flag to specify whether RPC endpoint supports block hash as block tag parameter // https://ethereum.org/en/developers/docs/apis/json-rpc/#default-block rpcSupportsBlockHashParam: boolean; + + // Enable ETH JSON RPC server at /rpc + enableEthRPCServer: boolean; } export interface FundingAmountsConfig { diff --git a/packages/util/src/server.ts b/packages/util/src/server.ts index 12ec71ee..af3e6feb 100644 --- a/packages/util/src/server.ts +++ b/packages/util/src/server.ts @@ -24,6 +24,7 @@ import { PaymentsManager, paymentsPlugin } from './payments'; const log = debug('vulcanize:server'); const DEFAULT_GQL_PATH = '/graphql'; +const ETH_RPC_PATH = '/rpc'; export const createAndStartServer = async ( app: Application, @@ -101,19 +102,25 @@ export const createAndStartServer = async ( path: gqlPath }); - // Create a JSON-RPC server to handle ETH RPC calls at /rpc - const rpcServer = jayson.Server(ethRPCHandlers); - - // Mount the JSON-RPC server to /rpc path - app.use( - '/rpc', - jsonParser(), - // TODO: Handle GET requests as well to match Geth's behaviour - rpcServer.middleware() - ); + if (serverConfig.enableEthRPCServer) { + // Create a JSON-RPC server to handle ETH RPC calls at /rpc + const rpcServer = jayson.Server(ethRPCHandlers); + + // Mount the JSON-RPC server to /rpc path + app.use( + ETH_RPC_PATH, + jsonParser(), + // TODO: Handle GET requests as well to match Geth's behaviour + rpcServer.middleware() + ); + } httpServer.listen(port, host, () => { - log(`Server is listening on ${host}:${port}${server.graphqlPath}`); + log(`GQL server is listening on http://${host}:${port}${server.graphqlPath}`); + + if (serverConfig.enableEthRPCServer) { + log(`ETH JSON RPC server is listening on http://${host}:${port}${ETH_RPC_PATH}`); + } }); return server;