node.js - 代理来自安全应用程序的请求

标签 node.js

我正在尝试代理来自 Node (它的内部应用程序)中的安全 Web 应用程序 (https) 的请求,但我不太确定该怎么做... 下面是我的代码,当我从不安全的应用程序 (http) 尝试它时,它可以工作。

它只是去掉一个页面名称并在另一个应用程序中使用它。我阅读了文档,但仍然不确定该怎么做。我需要从我的应用程序中获取 ssl 信息才能工作吗?

var http = require('http');
var httpProxy = require('http-proxy');
var request = require('request');
var app = require('express.io')();
app.http().io();

// 
// Create proxy server 
// 
var proxy = httpProxy.createProxyServer({target:'http://localhost:9000'}).listen(9085);

// Send the client html.
app.get('/', function(req, res) {

  res.sendfile(__dirname + '/client1.html');
})

proxy.on('error', function (err, req, res) {
  res.writeHead(500, {
    'Content-Type': 'text/plain'
  });
  res.end('Something went wrong!');
});

app.all('/Domain/*', function(req, res) {

  console.log(req.url);

   if (req.url.indexOf("Page.do") > -1) {

    // URL to Atlas
    var otherAppURL = "http://myotherapp/pages/";

    var temp = req.url.split("Page.do")[0].split("/");
    var pageName = temp[temp.length - 1];;

    app.io.broadcast('update', {
       url: atlasURL + pageName + '.html'
    }); 

   };


  // This doesnt work
  //var url = "https://mysecureapp:9044" + req.url;

  // This works
  var url = "http://localhost:9080" + req.url;   
  req.pipe(request(url)).pipe(res);

})

app.listen(9000);

最佳答案

是的,您确实需要 SSL 证书才能进行 HTTPS 连接。据网站https://www.globalsign.com/en/ssl-information-center/what-is-an-ssl-certificate/ :

The standard HTTP is changed to HTTPS, automatically telling the browser that the connection between the server and the browser must be secured using SSL.

这意味着对于 HTTPS 连接,您需要使用 SSL 保护服务器。 对于在 Node 中使用 HTTPS 连接,这个网站可能会帮助你: http://gaboesquivel.com/blog/2014/nodejs-https-and-ssl-certificate-for-development/

关于node.js - 代理来自安全应用程序的请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29448413/

相关文章:

node.js - 带有字符串而不是数组的nodejs spawn命令?

javascript - 服务器端未定义 renderProps/React/React-Router + Node/Express.js 的同构渲染

javascript - 聚合时传递字段和值

windows - 我可以在 Node.js 中设置 Windows 控制台宽度吗?

javascript - 在nodejs中发送消息太快 'net'

node.js - 如何等待 form-data node.js 模块中的管道完成?

node.js - Node.js 还支持 UDP 广播吗?

node.js - 使用 mongodb 中的函数保存 javascript 对象

node.js - 如何使用kurento在一对一视频通话中录制视频?

javascript - 遗漏或尝试后终于