【问题标题】:NodeJS: write http response with JavaScript contentNodeJS:用 JavaScript 内容编写 http 响应
【发布时间】:2018-10-30 23:08:13
【问题描述】:

我有一台服务器在端口 5000 上运行,而用户无权访问此端口。

我在 4000 上启动了另一个节点服务器,并想读取 http 内容 (localhost:5000/test)(内容有 javascripts),用户应该通过访问端口 localhost:4000/test 在浏览器上看到它

类似于 http 内容转发而不是 URL 转发。

有什么例子吗?提前致谢

【问题讨论】:

  • 您可以使用 NGINX 进行此操作,只需一个配置文件,无需编程。

标签: node.js http


【解决方案1】:


对于这个问题,我建议使用代理,例如 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); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-23
    • 2018-10-22
    • 2021-08-30
    • 1970-01-01
    • 2021-12-09
    • 2015-04-30
    • 2013-12-22
    • 2013-07-23
    相关资源
    最近更新 更多