hapi-mongodb 中的 SSL CA 证书详细信息
SSL CA certificate details in hapi-mongodb
我们不能在 MONGO URI 中指定 ssl 证书、密钥文件、密码短语详细信息吗?
例如:
mongodb://[username:password@]host1[:port1]][/[database][?cafile][&keyfile][&passphrase]]
为什么我问这个问题是因为我正在使用 hapi-mongodb
const Hapi = require('hapi');
const Boom = require('boom');
const launchServer = async function() {
const dbOpts = {
url: 'mongodb://localhost:27017/test',
settings: {
poolSize: 10
},
decorate: true
};
const server = Hapi.Server();
await server.register({
plugin: require('hapi-mongodb'),
options: dbOpts
});
await server.start();
console.log(`Server started at ${server.info.uri}`);
};
launchServer().catch((err) => {
console.error(err);
process.exit(1);
});
我找不到如何在 dbOpts
中添加 SSL 证书详细信息,例如 sslCA, sslKey, sslCert
?任何帮助将不胜感激。
https://github.com/Marsup/hapi-mongodb/blob/7e9cd65/lib/index.js#L38 读作:
const db = await MongoClient.connect(connectionOptions.url, connectionOptions.settings);
MongoClient.connect
的第二个参数记录在 http://mongodb.github.io/node-mongodb-native/2.2/reference/connecting/legacy-connection-settings/#individual-server-level-options
所以你的 dbOpts 必须类似于
const dbOpts = {
url: 'mongodb://localhost:27017/test',
settings: {
server: {
poolSize: 10,
sslKey:key,
sslCert:cert
}
},
decorate: true
};
我们不能在 MONGO URI 中指定 ssl 证书、密钥文件、密码短语详细信息吗?
例如:
mongodb://[username:password@]host1[:port1]][/[database][?cafile][&keyfile][&passphrase]]
为什么我问这个问题是因为我正在使用 hapi-mongodb
const Hapi = require('hapi');
const Boom = require('boom');
const launchServer = async function() {
const dbOpts = {
url: 'mongodb://localhost:27017/test',
settings: {
poolSize: 10
},
decorate: true
};
const server = Hapi.Server();
await server.register({
plugin: require('hapi-mongodb'),
options: dbOpts
});
await server.start();
console.log(`Server started at ${server.info.uri}`);
};
launchServer().catch((err) => {
console.error(err);
process.exit(1);
});
我找不到如何在 dbOpts
中添加 SSL 证书详细信息,例如 sslCA, sslKey, sslCert
?任何帮助将不胜感激。
https://github.com/Marsup/hapi-mongodb/blob/7e9cd65/lib/index.js#L38 读作:
const db = await MongoClient.connect(connectionOptions.url, connectionOptions.settings);
MongoClient.connect
的第二个参数记录在 http://mongodb.github.io/node-mongodb-native/2.2/reference/connecting/legacy-connection-settings/#individual-server-level-options
所以你的 dbOpts 必须类似于
const dbOpts = {
url: 'mongodb://localhost:27017/test',
settings: {
server: {
poolSize: 10,
sslKey:key,
sslCert:cert
}
},
decorate: true
};