我有一个服务器在 5000 端口上运行,但用户无权访问此端口。
我在 4000 上启动了另一个 Node 服务器,想读取 http 内容 (localhost:5000/test
)(内容有 javascripts),用户应该在浏览器访问端口 localhost:4000/test
类似于 http 内容转发而不是 URL 转发。
有什么例子吗?提前致谢
最佳答案
对于这个问题,我建议使用代理,例如 https://github.com/nodejitsu/node-http-proxy
您需要在端口 4000 上的服务器上实现的代码应如下所示:
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);
关于node.js - Node : write http response with JavaScript content,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53074126/