Ankur Soni
Ankur Soni

Reputation: 6018

SSL CA certificate details in hapi-mongodb

Can't we have ssl certificate, keyfile, passphrase details specified in MONGO URI?

FOR EXAMPLE:

mongodb://[username:password@]host1[:port1]][/[database][?cafile][&keyfile][&passphrase]]

Why I am asking this question is because I am using 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);
});

I cannot find how to add SSL Certificate details in dbOpts like sslCA, sslKey, sslCert? any help would be highly appreciated.

Upvotes: 0

Views: 226

Answers (1)

Alex Blex
Alex Blex

Reputation: 37048

https://github.com/Marsup/hapi-mongodb/blob/7e9cd65/lib/index.js#L38 reads:

const db = await MongoClient.connect(connectionOptions.url, connectionOptions.settings);

And the second parameter of MongoClient.connect is documented at http://mongodb.github.io/node-mongodb-native/2.2/reference/connecting/legacy-connection-settings/#individual-server-level-options

So your dbOpts must be something like

const dbOpts = {
    url: 'mongodb://localhost:27017/test',
    settings: {
        server: {
            poolSize: 10,
            sslKey:key,
            sslCert:cert
        }                
    },
    decorate: true
};

Upvotes: 1

Related Questions