Created
April 1, 2020 08:32
-
-
Save arkumish/49d1f769989569b4190c751bf7582b9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require("express"); | |
var app = express(); | |
app.get('/app1',function(req,res) { | |
res.send("Hello world From Server 1"); | |
}); | |
app.listen(8001); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require("express"); | |
var app = express(); | |
app.get('/app2',function(req,res) { | |
res.send("Hello world From Server 2"); | |
}); | |
app.listen(8002); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var app = express(); | |
var httpProxy = require('http-proxy'); | |
var request = require('request'); | |
var apiProxy = httpProxy.createProxyServer(); | |
var serverOne = 'http://localhost:8001', | |
ServerTwo = 'http://localhost:8002'; | |
app.all("/app1/*", function(req, res) { | |
console.log('redirecting to Server1'); | |
apiProxy.web(req, res, {target: serverOne}); | |
}); | |
app.all("/app2/*", function(req, res) { | |
console.log('redirecting to Server2'); | |
apiProxy.web(req, res, {target: ServerTwo}); | |
}); | |
app.all('/getmap',function(req,resp){ | |
request.get({ | |
url: 'https://maps.googleapis.com/maps/api/js?key=AIzaSyCCisTmeb2rhu32O7n2M6RF1iS6xWFbEH4', | |
json: true | |
},function(err,res,body){ | |
if(err)console.log(err); | |
else{ | |
console.log(res); | |
resp.send(res); | |
} | |
}); | |
}); | |
app.listen(8000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment