I'm trying to use Node.JS with http-proxy-middleware to build a proxy microservice because the Luminate Online API that the customer needs to use requires requests from a server with a static IP address added to their IP allow list, and the customer server can't have a static IP address for now.
So for the proxy microservice I created a server with a static IP address which was added to the API IP allow list. And I wrote this script to run on the server:
const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
require('dotenv').config();
const api_domain = process.env.LUMINATE_DOMAIN;
const api_anization = process.env.LUMINATE_ORGANIZATION;
const proxy_ip = process.env.PROXY_IP;
const app = express();
const proxyMiddleware = createProxyMiddleware({
target: 'https://'+api_domain,
changeOrigin: true,
onProxyReq: (proxyReq, req) => {
proxyReq.setHeader('X-Forwarded-For', proxy_ip);
proxyReq.setHeader('X-Real-IP', proxy_ip);
proxyReq.setHeader('Client-IP', proxy_ip);
},
pathRewrite: (path, req) => {
const newPath = `/${api_anization}/site/${req.params.path}`;
return newPath;
}
});
app.use('/site/:path(*)', proxyMiddleware);
app.listen(3000);
After properly executing the script and making a request from the customer server, the API response says: "Request not allowed from source IP address 170.246.33.111.".
Note: 170.246.33.111 is the customer server IP address, not the proxy server IP address.
Why is my script not successfully replacing origin IP address with the proxy server IP address? What could be wrong and how to fix it?