var https = require (' https '); var express = require (' Express '); var app = Express () var http = require (' http '), httpproxy = Require (' Http-proxy '); var proxy = Httpproxy.createproxyserver ({changeorigin:true}); App.all ('/apis/* ', function (req, res, next) { var target = req.originalUrl.replace ("/apis/", ""); Change the This API URL to suit your project var url = '/${target} '; Req.url = URL; Console.log (URL); Delete Req.headers.host; Proxy.web (req, res, {target: ' http://localhost ', changeorigin:true}); }) var server = App.listen (8080, function () { var host = Server.address (). Address; var port = server.address (). Port; Console.log (' Example app listening at http://%s:%s ', host, Port);});
Changeorigin:true and Req.url = ' processed URL '
var https = require (' https '); var express = require (' Express '); var app = Express () var http = require (' http '), Httpproxy = Require (' Http-proxy '); var proxy = Httpproxy.createproxyserver ({changeorigin:true});
App.all ('/apis/* ', function (req, res, next) {var target = Req.originalUrl.replace ("/apis/", ""); Change the This API URL to suit your project var url = '/${target} '; Req.url = URL; Console.log (URL); Delete Req.headers.host; Proxy.web (req, res, {target: ' http://localhost ', changeorigin:true}); })
var server = App.listen (8080, function () {var host = Server.address (). Address; var port = server.address (). Port; Console.log (' Example app listening at http://%s:%s ', host, Port);});
Nodejs Http-proxy Agent Practical application