0
Good afternoon, I am creating a Proxy for an application. What is intended is to centralize a set of API’s and forward requests.
I’m doing a basic example in nodejs. Where I have 2 servers:
- Server 1 (Proxy Server)
- Server 2 (Other API)
Index:
const http = require("http");
const appServer1 = require("./server1");
const appServer2 = require("./server2");
const server1 = http.createServer(appServer1);
const server2 = http.createServer(appServer2);
server1.listen(3001);
server2.listen(3002);
Server 1:
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
app.use(bodyParser.json());
app.post("/upload", function(req, res) {
res.json({});
});
module.exports = app;
Server 2:
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
app.use(bodyParser.json());
app.post("/uploadOther", function(req, res) {
res.json({});
});
module.exports = app;
What I wanted to do was forward for example the request http://localhost:3001/upload for http://localhost:3002/uploadOther, without having to save the file for example. Someone can help me?
Maybe the Nodejs is not the best option for reverse proxy, but... you can try with the http-proxy + Expressjs
– Valdeir Psr
take a look at this example https://itnext.io/hosting-multiple-apps-on-the-same-server-implement-a-reverse-proxy-with-node-a4e213497345
– Marcelo Batista