mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-04-14 19:56:23 +00:00
* add run-rs to dependencies * wip: add replica set to api unit github action * wip: add replica set to api unit github action * wip: fix gh actions mongodb replica set setting * usa replica set for integration tests * add correct mongodb version matrix for integration tests * use different db connection on gh actions * Revert "use different db connection on gh actions" This reverts commit aa8db759d380ba58ac90304c786b3eba5004b1bd. * add example transaction * add mongo script to package.json * abstract mongodb utils, connect using hostname on windows * npm scripts: mongo -> mongo:dev * add setup script for run-rs on windows * gh actions: run in test environment * remove test files * better error handling, use cross-spawn to avoid issues on windows * fix lint
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
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 () {
|
|
const commonOptions = {
|
|
useNewUrlParser: true,
|
|
useUnifiedTopology: true,
|
|
};
|
|
|
|
return !IS_PROD ? commonOptions : {
|
|
// See https://mongoosejs.com/docs/connections.html#keepAlive
|
|
keepAlive: true,
|
|
keepAliveInitialDelay: 300000,
|
|
...commonOptions,
|
|
};
|
|
}
|