gpt4 book ai didi

javascript - 无法使用 loopbackjs 验证 nodejs 中的第一个证书

转载 作者:行者123 更新时间:2023-11-30 19:56:01 26 4
gpt4 key购买 nike

在下面的代码中,我试图检查 UUID 是否已经生成。我尝试使用 https.request 而不是 https.get 来检查可能是错误已解决但结果是一样的。此外,我在 https.request 中添加了 keycrt 用于 loopback SSL config 以传递问题,但没有出现差异。

const options = {
hostname: 'app.mydomain.com', //same as localhost:3000
port: 443,
path: '/api/uuids?filter[where][uuid]=' + UUID,
method: 'GET',

key: fs.readFileSync(path.join(__dirname, './../../server/ssl/domain.key')),
cert: fs.readFileSync(path.join(__dirname, './../../server/ssl/domain.crt'))
};
console.log(options);
const req = https.request(options, (res) => {

res.on('data', (d) => {
d = JSON.parse(d)
console.log(d);
if (d.length == 1 && d[0].uuid == UID) {

return 200;
}
else {
return 500;
}
});
});

req.on('error', (e) => {
console.error(e);
});

控制台错误:

(node:4452) [DEP0079] DeprecationWarning: Custom inspection function on Objects via .inspect() is deprecated
{ Error: unable to verify the first certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1049:34)
at TLSSocket.emit (events.js:182:13)
at TLSSocket._finishInit (_tls_wrap.js:631:8) code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' }

我也尝试过使用:

    const https = require('https').globalAgent.options.ca = require('ssl-root-cas/latest').create();

In the declaration of `https` but the following error appears:

(node:4500) [DEP0079] DeprecationWarning: Custom inspection function on Objects via .inspect() is deprecated
Unhandled error for request POST /registrations: TypeError: https.request is not a function
at checkUUID (C:\apps\app\common\models\registration.js:60:20)
at C:\apps\app\common\models\registration.js:16:17
at notifySingleObserver (C:\apps\app\node_modules\loopback-datasource-juggler\lib\observer.js:160:22)
at C:\apps\app\node_modules\async\dist\async.js:3110:16
at replenish (C:\apps\app\node_modules\async\dist\async.js:1011:17)
at C:\apps\app\node_modules\async\dist\async.js:1016:9
at eachLimit$1 (C:\apps\app\node_modules\async\dist\async.js:3196:24)
at Object.<anonymous> (C:\apps\app\node_modules\async\dist\async.js:1046:16)
at doNotify (C:\apps\app\node_modules\loopback-datasource-juggler\lib\observer.js:157:11)
at doNotify (C:\apps\app\node_modules\loopback-datasource-juggler\lib\observer.js:155:49)
at doNotify (C:\apps\app\node_modules\loopback-datasource-juggler\lib\observer.js:155:49)
at doNotify (C:\apps\app\node_modules\loopback-datasource-juggler\lib\observer.js:155:49)
at Function.ObserverMixin._notifyBaseObservers (C:\apps\app\node_modules\loopback-datasource-juggler\lib\observer.js:178:5)
at Function.ObserverMixin.notifyObserversOf (C:\apps\app\node_modules\loopback-datasource-juggler\lib\observer.js:153:8)
at Function.ObserverMixin._notifyBaseObservers (C:\apps\app\node_modules\loopback-datasource-juggler\lib\observer.js:176:15)
at Function.ObserverMixin.notifyObserversOf (C:\apps\app\node_modules\loopback-datasource-juggler\lib\observer.js:153:8)

附加信息

  • 我将我的个人服务器用作 vps/专用服务器
  • 我将 Nginx 与 app.mydomain.com mydomain.com 的代理服务器一起使用 +wwww.mydomain.com + app.mydomain.com 所有这些都可以通过以下方式访问只有 ssl端口 443
  • 我使用 zerossl 为我的域和子域获取证书。
  • 我使用了网站为
    生成的相同 key 证书loopbackjs ssl 配置

最佳答案

2 天后我找到了解决方法,我使用了这些代码:

var rootCas = require('ssl-root-cas/latest').create();
rootCas.addFile(__dirname + './../../server/ssl/domain.crt');
const https = require('https');//.globalAgent.options.ca = require('ssl-root-cas/latest').create();
var request = require('request');

 const options = {
hostname: 'app.mydomain.com',
port: 443,
path: '/api/uuids?filter[where][uuid]=' + UID,
method: 'GET',
key: fs.readFileSync(path.join(__dirname, './../../server/ssl/domain.key')),
cert: fs.readFileSync(path.join(__dirname, './../../server/ssl/domain.crt'))
};
const req = https.get(options, (res) => {
res.on('data', (d) => {
d = JSON.parse(d)
if (d.length == 1 && d[0].uuid == UID) {

return 200;
}
else {
return 500;
}
});
});

req.on('error', (e) => {
console.error(e);
});

关于javascript - 无法使用 loopbackjs 验证 nodejs 中的第一个证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53984616/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com