If the browser reaches the development server but its API request fails, configure the connection made by the middleware:

const { createProxyMiddleware } = require('http-proxy-middleware');
const { HttpsProxyAgent } = require('https-proxy-agent');

app.use('/api', createProxyMiddleware({
  target: 'https://api.example',
  changeOrigin: true,
  agent: new HttpsProxyAgent('http://proxy.example:8080'),
}));

app is the existing Express application. This uses the modern middleware factory and named HttpsProxyAgent export; retain the intended path mapping and access controls.

target names the API. agent identifies the intermediary and negotiates the tunnel for that HTTPS target. Using the corporate proxy URL as target asks for another application rather than adding a hop.

Use an agent appropriate to the target protocol and a listener that actually supports the needed HTTP proxy interface. For an approved private CA on that route, configure trust through the Node transport with verification enabled. secure: false changes verification instead of selecting the intermediary.

Artiglyn mynjee