Restore JSON client returns error DEPTH_ZERO_SELF_SIGNED_CERT

I have a server running heroku SSL applications on the hero with the admin. The server is created using the following parameters:

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

And I start the server as follows:

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

And everything works fine, I can name the api, for example: https://myapp.herokuapp.com/some-path . The heroku SSL certificate is in itself, so there is a big warning in webbrowser, but I can click continue and it works.

When I want to call my server using JSON client recovery, create it like this:

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

and then call some api, like this client.get('/some-path',...) , then the client returns an error:

 DEPTH_ZERO_SELF_SIGNED_CERT 

I tried to set the rejectUnauthorized option both on the server and on the client (as a constructor option), but it did not help ...

+4
source share
2 answers

I just tested on my own HTTPS server with a self-signed certificate. rejectUnauthorized client-side will definitely solve it for you

 var restify = require('restify'), client = restify.createJsonClient({ url: 'https://127.0.0.1/booking', rejectUnauthorized: false }), assert = require('assert'); describe('/booking/ component\ 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(); }); }); }); 

As soon as I remove the rejectUnauthorized option, the test will fail with the DEPTH_ZERO_SELF_SIGNED_CERT error.

+4
source

For me, rejectUnauthorized did not work. Finally, I finished:

 process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; 

And it works ...

+3
source

Source: https://habr.com/ru/post/1501172/


All Articles