2020-07-14 16:55:47 +00:00
|
|
|
import os from 'os';
|
|
|
|
|
import nconf from 'nconf';
|
|
|
|
|
|
|
|
|
|
const IS_PROD = nconf.get('IS_PROD');
|
|
|
|
|
|
|
|
|
|
// Due to some limitation in the `run-rs` module that is used in development
|
|
|
|
|
// In order to connect to the database on Windows the hostname must be used
|
|
|
|
|
// instead of `localhost`.
|
|
|
|
|
// See https://github.com/vkarpov15/run-rs#notes-on-connecting
|
|
|
|
|
// for more info.
|
|
|
|
|
//
|
|
|
|
|
// This function takes in a connection string and in case it's being run on Windows
|
|
|
|
|
// it replaces `localhost` with the hostname.
|
|
|
|
|
export function getDevelopmentConnectionUrl (originalConnectionUrl) {
|
|
|
|
|
const isWindows = os.platform() === 'win32';
|
|
|
|
|
|
|
|
|
|
if (isWindows) {
|
|
|
|
|
const hostname = os.hostname();
|
|
|
|
|
return originalConnectionUrl.replace('mongodb://localhost', `mongodb://${hostname}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return originalConnectionUrl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getDefaultConnectionOptions () {
|
2024-02-05 22:50:06 +00:00
|
|
|
// with keepAlive deprecated, we don't need a separate set of production options
|
|
|
|
|
// Keeping the structure here in case the distinction is useful later
|
2020-07-14 16:55:47 +00:00
|
|
|
const commonOptions = {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return !IS_PROD ? commonOptions : {
|
|
|
|
|
...commonOptions,
|
|
|
|
|
};
|
|
|
|
|
}
|