restify JSON 客户端返回DEPTH_ZERO_SELF_SIGNED_CERT错误



我有服务器在heroku上运行,带有heroku SSL插件。使用以下选项创建服务器:

name: 'ServerName',
version: '1.0.0',

我像这样运行服务器:

    server.listen(process.env.PORT || 5000)

它工作正常,我可以调用我的 api,例如:https://myapp.herokuapp.com/some-path。heroku 上的 SSL 证书是自签名的,因此网络浏览器中有一个很大的警告,但我可以单击继续并且它可以工作。

当我想使用 restify JSON 客户端调用我的服务器时,创建如下:

var client   = restify.createJsonClient({
    url: 'https://myapp.herokuapp.com'
});

然后像这样调用一些 API client.get('/some-path',...)然后客户端返回错误:

DEPTH_ZERO_SELF_SIGNED_CERT

我尝试在服务器和客户端上设置选项 rejectUnauthorized(作为构造函数选项),但它没有帮助......

我刚刚在自己的HTTPS服务器上使用自签名证书进行了测试。 客户端rejectUnauthorized绝对应该为您解决

var restify = require('restify'),
    client = restify.createJsonClient({
        url: 'https://127.0.0.1/booking',
        rejectUnauthorized: false
    }),
    assert = require('assert');
describe('/booking/ component's JSON-HAL HTTP API description', function () {
    it('responds with status 200', function (done) {
        client.get('/', function (error, request, response) {
            assert(!error);
            assert.strictEqual(response.statusCode, 200);
            done();
        });
    });
});

一旦我删除rejectUnauthorized选项,测试就会失败并显示DEPTH_ZERO_SELF_SIGNED_CERT.

对我来说

rejectUnauthorized不起作用。最后我得到:

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

它有效...

相关内容

最新更新