在下面的代码中,我试图检查UUID
是否已经生成。我尝试使用https.request
而不是https.get
来检查是否可以解决错误,但结果是相同的。另外,我在key
中使用了crt
中的https.request
和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)
其他信息
ssl
和port 443
。key
和cert
,loopbackjs ssl config
答案 0 :(得分:1)
两天后,我找到了解决方法,我使用了以下代码:
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);
});