我正在使用 node-slack 将 Mattermost 传入 URL Api 用于自托管的mattermost。这最重要的是通过让加密来保护的。
我的节点代码正在使用 slack api,并且我已经使用 Postman(手动发布工具)针对 MM 服务器测试了发送数据。
在这两种情况下,它都在工作。
但是使用节点我收到一个 unable to verify the first certificate错误。
在“ https://nodejs.org/api/https.html ”中,我可以看到,node.js 支持一组“众所周知的”根 CA。
为了简化问题,我写了这个小小的和平代码:
let request = require('request');
request("https:--letsencryptsecuredsite",function(err,body){
console.log(err);
console.log(body);
});
Run Code Online (Sandbox Code Playgroud)
这导致
{ Error: unable to verify the first certificate
at Error (native)
at TLSSocket.<anonymous> (_tls_wrap.js:1079:38)
at emitNone (events.js:86:13)
at TLSSocket.emit (events.js:185:7)
at TLSSocket._finishInit (_tls_wrap.js:603:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:433:38) code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' }
Run Code Online (Sandbox Code Playgroud)
我必须在让加密安全的服务器上使用 API 吗?
我正在使用节点版本 6.9.2。
在我的项目中,我尝试扩展推文以完全显示.由bit.ly缩短的链接通过代码的平衡扩展(找到@ stackoverflow).
function expandUrl(shortUrl,callback) {
debug("expandUrl");
request( { method: "HEAD", url: shortUrl, followAllRedirects: true },
function (error, response) {
if (error) return callback(null,shortUrl);
return callback(null,response.request.href);
}
);
}
Run Code Online (Sandbox Code Playgroud)
为了不需要在mocha测试期间联机,我想用以下内容来解决这部分代码:
nock('http://bit.ly')
.intercept("/1Ghc7dI","HEAD")
.reply(200,undefined,{location:"http://discoverspatial.com/courses/qgis-for-beginners"});
Run Code Online (Sandbox Code Playgroud)
但这不起作用.在这个工作之后,response.request.href是"未定义的".(我试过href而不是位置,这没什么区别.