简体   繁体   中英

NodeJS: write http response with JavaScript content

I have a server running on port 5000 and users don't have access to this port.

I started another node server on 4000 and want to read the http content ( localhost:5000/test ) (content has javascripts) and users should see it on the browser by accessing port localhost:4000/test

Something like http content forward not the URL forward.

Any examples? Thanks in advance


For this problem, I would recommend using a proxy such as https://github.com/nodejitsu/node-http-proxy
The code that you would need to implement on your server on port 4000 should look something like this:

const http = require('http'),
    httpProxy = require('http-proxy');
//
// Create your proxy server and set the target in the options.
//
httpProxy.createProxyServer({target:'http://localhost:5000'}).listen(4000); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM