I am trying to implement a node.js layer between two servers which will help in redirecting to the respective server on a route/url change, provided both the servers are inside one folder.
What I wanted to achieve:
If I hit localhost:8000/app1 --> server1 should be called
similarly, localhost:8000/app2 --> server2 should be called
So far I have tried:
const path = require("path");
const express = require("express");
const router = express.Router();
const PORT = 8000;
const server1 = require('./server1')
const server2 = require('./server2')
app.get('/app1', function(req, res){
res.send(server1);
});
app.get('/app2', function(req, res){
res.send(server2);
});
app.listen(PORT, function(err){
if (err) console.log(err);
console.log("Server listening on PORT", PORT);
I have also tried to understand express vhost in this scenario but did not got any success.
I would love to understand if this is possible?