sbpothineni
sbpothineni

Reputation: 85

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

Upvotes: 1

Views: 59

Answers (1)

Dream Streamer
Dream Streamer

Reputation: 71


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); 

Upvotes: 2

Related Questions