Intercepting and redirecting an SSE request to a proxy server

109 views Asked by At

I have a script, and I need to intercept and redirect a request to a proxy server.

const originalDestination = 'http://localhost:3004';
const newDestination = 'http://localhost:3005'; // proxy

In my case, the problem is that it's a Server-Sent Events (SSE) request.

I tried using nock to intercept the request, but when using axios.get, the request just hangs.

nock(originalDestination)
  .persist()
  .get(/.*/)
  .reply(async (uri: string, requestBody: any) => {
    const response = await axios.get(`${newDestination}${uri}`);
    return [response.status, response.data, response.headers];
  });

Are there any other options for intercepting and redirecting the request, or how can I modify the nock code?

0

There are 0 answers