admin管理员组文章数量:1394201
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?
本文标签:
版权声明:本文标题:How to create a proxy that replaces the origin IP address with the proxy server IP address using Node.JS? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744629577a2616457.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论