Removed mongoose.uri and mongoose.database options for single mongoose.connection_string

This commit is contained in:
Jonathan Barrow 2022-10-20 20:29:23 -04:00
parent 36fd3d1596
commit 0cebd41f5c
No known key found for this signature in database
GPG key ID: E86E9FE9049C741F
4 changed files with 7 additions and 13 deletions

View file

@ -3,8 +3,7 @@
"port": 7070
},
"mongoose": {
"uri": "mongodb://localhost:27017",
"database": "database_name",
"connection_string": "mongodb://localhost:27017/database_name",
"options": {
"useNewUrlParser": true
}

View file

@ -1,7 +1,6 @@
PN_ACT_PREFER_ENV_CONFIG=true # Load config from ENV instead of config.json
PN_ACT_CONFIG_HTTP_PORT=7070
PN_ACT_CONFIG_MONGO_URI=mongodb://localhost:27017
PN_ACT_CONFIG_MONGO_DB_NAME=database_name
PN_ACT_CONFIG_MONGO_CONNECTION_STRING=mongodb://localhost:27017/database_name
PN_ACT_CONFIG_MONGOOSE_OPTION_useNewUrlParser=true
PN_ACT_CONFIG_MONGOOSE_OPTION_useUnifiedTopology=true
PN_ACT_CONFIG_REDIS_URL=redis://localhost:6379

View file

@ -10,8 +10,7 @@ require('dotenv').config();
* @property {object} http HTTP server settings
* @property {number} http.port HTTP port the server will listen on
* @property {object} mongoose Mongose connection settings
* @property {string} mongoose.uri URI Mongoose will connect to
* @property {string} mongoose.database MongoDB database name
* @property {string} mongoose.connection_string MongoDB connection string
* @property {object} mongoose.options MongoDB connection options
* @property {object} [redis] redis settings
* @property {string} [redis.client] redis client settings
@ -42,7 +41,6 @@ require('dotenv').config();
*/
let config = {};
/**
* @typedef {Object} DisabledFeatures
* @property {boolean} redis true if redis is disabled
@ -63,8 +61,7 @@ const disabledFeatures = {
const requiredFields = [
['http.port', 'PN_ACT_CONFIG_HTTP_PORT', Number],
['mongoose.uri', 'PN_ACT_CONFIG_MONGO_URI'],
['mongoose.database', 'PN_ACT_CONFIG_MONGO_DB_NAME'],
['mongoose.connection_string', 'PN_ACT_CONFIG_MONGO_CONNECTION_STRING'],
['cdn.base_url', 'PN_ACT_CONFIG_CDN_BASE_URL']
];
@ -79,8 +76,7 @@ function configure() {
port: Number(process.env.PN_ACT_CONFIG_HTTP_PORT)
},
mongoose: {
uri: process.env.PN_ACT_CONFIG_MONGO_URI,
database: process.env.PN_ACT_CONFIG_MONGO_DB_NAME,
connection_string: process.env.PN_ACT_CONFIG_MONGO_CONNECTION_STRING,
options: Object.keys(process.env)
.filter(key => key.startsWith('PN_ACT_CONFIG_MONGOOSE_OPTION_'))
.reduce((obj, key) => {

View file

@ -6,7 +6,7 @@ const { PNID } = require('./models/pnid');
const { Server } = require('./models/server');
const logger = require('../logger');
const { config } = require('./config-manager');
const { uri, database, options } = config.mongoose;
const { connection_string, options } = config.mongoose;
// TODO: Extend this later with more settings
const discordConnectionSchema = joi.object({
@ -16,7 +16,7 @@ const discordConnectionSchema = joi.object({
let connection;
async function connect() {
await mongoose.connect(`${uri}/${database}?replicaSet=rs0`, options);
await mongoose.connect(connection_string, options);
connection = mongoose.connection;
connection.on('error', console.error.bind(console, 'connection error:'));