mockthereum icon indicating copy to clipboard operation
mockthereum copied to clipboard

Allow proxyTo with path

Open dappvibe opened this issue 2 months ago • 1 comments

Many RPC endpoints require path, both public like https://arb1.arbitrum.io/rpc and private to include API key arb-mainnet.g.alchemy.com/v2/your-key-here.

getLocal({
    unmatchedRequests: { proxyTo: 'https://arb1.arbitrum.io/rpc' }
})

This fails. Is there a workaround?

dappvibe avatar Nov 25 '25 18:11 dappvibe

Nice suggestion! Right now no, that's not possible, but it's a good idea. I'm not actively working on this repo right now but I'd be happy to review a patch for this if you want to add support. There would be a few steps required:

  • Update from Mockttp v3 to v4
  • Swap .thenForwardTo (which only supports protocols & hostnames) for something like:
    .thenPassThrough({
      transformRequest: {
        setProtocol: ...,
        replaceHost: { targetHost: ... },
        matchReplacePath: [
          [/.*/, ...]
        ]
      }
    });
    
    These transforms are only supported in v4+, which is why that update is required). You'll need to parse the proxyTo argument to extract the ... values you'll need here.
  • Add a test in https://github.com/httptoolkit/mockthereum/blob/main/test/integration/proxy.spec.ts to cover this, making sure the existing tests still pass as well.

pimterry avatar Nov 26 '25 13:11 pimterry