【发布时间】:2015-07-22 12:18:21
【问题描述】:
我正在尝试让 node-http-proxy 与 AppJS 一起工作。不幸的是,它在启动应用程序时崩溃。我做了什么:
- 从http://appjs.com/下载并提取AppJS;
- 使用 npm install http-proxy 安装 node-http-proxy;
-
编辑了 app.js 的 window.on(create) 函数:
window.on('create', function(){ console.log("Window Created"); window.frame.show(); window.frame.center(); window.frame.setMenuBar(menubar); var http = require('http'), httpProxy = require('http-proxy'); // // Create your proxy server and set the target in the options. // httpProxy.createProxyServer({target:'http://localhost:9000'}).listen(8000); // // Create your target server // http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2)); res.end(); }).listen(9000); });
当应用程序启动时,我想启动 nodeJS 代理服务器。是否可以从外部 PC 连接到此代理服务器? (我知道我需要为此打开端口)
例如,如果我在家用 PC 上运行应用程序并且在工作中,我会将工作 PC 的代理设置设置为 homePC_IP:8000。这行得通吗?
【问题讨论】:
-
你试过了吗?你有理由相信它不会起作用吗?
-
我确实尝试过,当我使用 locahost:8080 作为代理时,它可以工作。当我用我的手机在 4G 上设置一个 Wifi 热点并使用我的家庭 IP:8080 时它不起作用,我确实在我的路由器上打开了端口 8080 和端口 80。我错过了一步吗?
-
经过深思熟虑后,我知道为什么上面没有工作:) 我使用了设置代理服务器的同一台 PC.... 但是我仍然无法弄清楚为什么 AppJS 在我崩溃时崩溃添加启动节点-http-proxy?此处提供的代码:catonmat.net/http-proxy-in-nodejs 确实有效,但不适用于 https :( 有人建议 node-http-proxy 出了什么问题?
标签: node.js proxy server appjs