我想将REST请求从我的前端wepp应用转移到外部Jira服务器上的API。节点http-proxy:将流量转发到外部https站点 - 崩溃
为此,我使用节点http-proxy,这对于Jira服务器来说是可以使用的。
但是现在我想为https创建一个单独的服务器。
所以使得SOM更改this比如我现在有这样的:
var path = require('path'),
fs = require('fs'),
httpProxy = require('http-proxy'),
certFolder = '/my/cert/folder';
//
// Create the HTTPS proxy server listening on port 8002
//
httpProxy.createServer({
//(placeholder address)
target: {
host: 'https://ext.jiraserver.com',
port: 443
},
// letsencrypt cert
ssl: {
key: fs.readFileSync(path.join(certFolder, 'privkey.pem'), 'utf8'),
cert: fs.readFileSync(path.join(certFolder, 'fullchain.pem'), 'utf8')
},
secure: true
}).listen(8002);
console.log('https proxy server started on port 8002');
但是,当我做我的服务器发出请求,https://my.domain.com:8002崩溃与错误消息的服务器:
.../node_modules/http-proxy/lib/http-proxy/index.js:119 throw err; ^
Error: getaddrinfo ENOTFOUND https://ext.jiraserver.com https://ext.jiraserver.com:443 at errnoException (dns.js:28:10) at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
我似乎无法得到它的工作...服务器在线和地址是正确的,所以我不知道什么是错的。
它是我的代码是错的,或者我能做些什么才能使它工作?
谢谢!
我试过了,我只得到:400错误请求 - 纯HTTP请求被发送到HTTPS端口。大家都觉得httpProxy已经启动了一个http服务器,而不是https? – mottosson
@mottosson尝试在'target'配置中添加'https:true'。 – cgTag
我做了,但仍然是相同的错误消息...: - \ – mottosson