node.js - Node : write http response with JavaScript content

标签 node.js http

我有一个服务器在 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/

相关文章:

rest - 通过 npm 注册表 REST api 获取有关我的私有(private) npm 包的信息

angularjs - 使用 $http 发送带有 Angular 的多部分/表单数据文件

android - JSON解析成textview Android

node.js - 如何了解Firebase云函数中的新数据?

javascript - 如何将 Node.js 应用程序转换为 exe?

http - flutter x-www-form-urlencoded POST 请求

http - 服务器崩溃 = 在此之后 TCP/IP(和浏览器客户端)的行为如何?

node.js - Node REPL : how to break out of . ..?

node.js - 向 module.exports 添加参数?

javascript - 如果在 EnsureIndex MongoDB Node 中发现重复则显示错误