[英]NodeJS: write http response with JavaScript content
我有一台运行在端口5000上的服务器,用户无权访问此端口。
我在4000上启动了另一个节点服务器,并想读取http内容( localhost:5000/test
)(内容包含JavaScript),用户应该通过访问端口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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.