diff --git a/server/.github/test.conf.json5 b/server/.github/test.conf.json5 index 4265d9963..84f98670a 100644 --- a/server/.github/test.conf.json5 +++ b/server/.github/test.conf.json5 @@ -1,7 +1,8 @@ // Config file that the CI deployment uses. This is moved to $pwd/conf.json5 before CI tests are ran. { - MONGO_BASE_URL: "127.0.0.1", + MONGO_CONNECTION_URL: "127.0.0.1:27017", + MONGO_DATABASE_NAME: "testingdb", LOG_LEVEL: "info", CAPTCHA_SECRET_KEY: "unused", SESSION_SECRET: "unused", diff --git a/server/src/external/mongo/db.ts b/server/src/external/mongo/db.ts index 35139c420..7dcd96706 100644 --- a/server/src/external/mongo/db.ts +++ b/server/src/external/mongo/db.ts @@ -27,16 +27,13 @@ import { ImportLockDocument, } from "tachi-common"; import monk from "monk"; -import { MONGO_BASE_URL } from "../../lib/setup/config"; +import { MONGO_CONNECTION_URL, MONGO_DATABASE_NAME } from "../../lib/setup/config"; import CreateLogCtx from "../../lib/logger/logger"; import { OrphanScoreDocument } from "../../lib/score-import/import-types/common/types"; const logger = CreateLogCtx(__filename); -/* istanbul ignore next */ -const base = MONGO_BASE_URL ?? "127.0.0.1"; - -let dbName = "ktblackdb"; +let dbName = MONGO_DATABASE_NAME; /* istanbul ignore next */ if (process.env.NODE_ENV === "test") { @@ -47,16 +44,14 @@ if (process.env.NODE_ENV === "test") { } } -const url = `mongodb://${base}:27017/${dbName}`; - let dbtime: [number, number] = [0, 0]; /* istanbul ignore next */ if (process.env.NODE_ENV !== "test") { - logger.info(`Connecting to database ${url}...`); + logger.info(`Connecting to database ${MONGO_CONNECTION_URL}/${dbName}...`); dbtime = process.hrtime(); } -export const monkDB = monk(url); +export const monkDB = monk(`${MONGO_CONNECTION_URL}/${dbName}`); /* istanbul ignore next */ monkDB diff --git a/server/src/lib/setup/config.ts b/server/src/lib/setup/config.ts index 9a979b986..c3f456676 100644 --- a/server/src/lib/setup/config.ts +++ b/server/src/lib/setup/config.ts @@ -26,7 +26,8 @@ function isValidURL(self: unknown) { } export interface TachiConfig { - MONGO_BASE_URL: string; + MONGO_CONNECTION_URL: string; + MONGO_DATABASE_NAME: string; LOG_LEVEL: "debug" | "verbose" | "info" | "warn" | "error" | "severe" | "crit"; CAPTCHA_SECRET_KEY: string; SESSION_SECRET: string; @@ -44,7 +45,8 @@ export interface TachiConfig { } const err = p(config, { - MONGO_BASE_URL: "string", + MONGO_CONNECTION_URL: "string", + MONGO_DATABASE_NAME: "string", LOG_LEVEL: p.isIn("debug", "verbose", "info", "warn", "error", "severe", "crit"), CAPTCHA_SECRET_KEY: "string", SESSION_SECRET: "string", @@ -98,7 +100,8 @@ if (config.TYPE === "ktchi") { const tachiConfig = config as TachiConfig; -export const MONGO_BASE_URL = tachiConfig.MONGO_BASE_URL; +export const MONGO_CONNECTION_URL = tachiConfig.MONGO_CONNECTION_URL; +export const MONGO_DATABASE_NAME = tachiConfig.MONGO_DATABASE_NAME; export const LOG_LEVEL = tachiConfig.LOG_LEVEL; export const SESSION_SECRET = tachiConfig.SESSION_SECRET; export const CAPTCHA_SECRET_KEY = tachiConfig.CAPTCHA_SECRET_KEY;