Skip to content

Commit

Permalink
add dedicated ws endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
samepant committed Oct 3, 2024
1 parent 0515661 commit 81ccad8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/lib/rpc-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export type RPCNode = {
username?: string;
password?: string;
url: string;
socketUrl: string;
};

export type RPCNodes = {
Expand All @@ -14,47 +15,55 @@ export const rpcNodes: RPCNodes = {
username: process.env.MAINNET_RPC_USERNAME,
password: process.env.MAINNET_RPC_PASSWORD,
url: "https://ethereum-mainnet.core.chainstack.com",
socketUrl: "wss://ethereum-mainnet.core.chainstack.com",
},
42161: {
//arbitrum
username: process.env.ARBITRUM_RPC_USERNAME,
password: process.env.ARBITRUM_RPC_PASSWORD,
url: "https://arbitrum-mainnet.core.chainstack.com",
socketUrl: "wss://arbitrum-mainnet.core.chainstack.com",
},
43114: {
//avalanche
username: process.env.AVALANCHE_RPC_USERNAME,
password: process.env.AVALANCHE_RPC_PASSWORD,
url: "https://avalanche-mainnet.core.chainstack.com/ext/bc/C/rpc",
socketUrl: "wss://avalanche-mainnet.core.chainstack.com/ext/bc/C/ws",
},
10: {
//optimism
username: process.env.OPTIMISM_RPC_USERNAME,
password: process.env.OPTIMISM_RPC_PASSWORD,
url: "https://nd-007-647-713.p2pify.com",
socketUrl: "wss://ws-nd-007-647-713.p2pify.com",
},
137: {
//polygon
username: process.env.POLYGON_RPC_USERNAME,
password: process.env.POLYGON_RPC_PASSWORD,
url: "https://polygon-mainnet.core.chainstack.com",
socketUrl: "wss://polygon-mainnet.core.chainstack.com",
},
8453: {
//base
username: process.env.BASE_RPC_USERNAME,
password: process.env.BASE_RPC_PASSWORD,
url: "https://nd-092-619-550.p2pify.com",
socketUrl: "wss://ws-nd-092-619-550.p2pify.com",
},
100: {
//gnosis
username: process.env.GNOSIS_RPC_USERNAME,
password: process.env.GNOSIS_RPC_PASSWORD,
url: "https://nd-696-263-600.p2pify.com",
socketUrl: "wss://ws-nd-696-263-600.p2pify.com",
},
11155111: {
//sepolia
username: process.env.SEPOLIA_RPC_USERNAME,
password: process.env.SEPOLIA_RPC_PASSWORD,
url: "https://ethereum-sepolia.core.chainstack.com",
socketUrl: "wss://ethereum-sepolia.core.chainstack.com",
},
};
13 changes: 13 additions & 0 deletions src/routes/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ const generateChainRoutes = (router: Router) => {
[`^/api/v1/${chainId}/rpc`]: "",
},
auth: `${chain.rpcNode.username}:${chain.rpcNode.password}`,
}),
);

// Create WebSocket Proxy routes for each chain
router.use(
`/${chainId}/rpc/ws`,
createProxyMiddleware({
target: chain.rpcNode.socketUrl,
changeOrigin: true,
pathRewrite: {
[`^/api/v1/${chainId}/rpc/ws`]: "",
},
auth: `${chain.rpcNode.username}:${chain.rpcNode.password}`,
ws: true,
}),
);
Expand Down

0 comments on commit 81ccad8

Please sign in to comment.