mockthereum
mockthereum copied to clipboard
Allow proxyTo with path
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?
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:
These transforms are only supported in v4+, which is why that update is required). You'll need to parse the.thenPassThrough({ transformRequest: { setProtocol: ..., replaceHost: { targetHost: ... }, matchReplacePath: [ [/.*/, ...] ] } });proxyToargument 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.