This commit is contained in:
Alex Holliday committed 2026-03-26 09:47:10 -07:00
1 parent e87879970a
commit be29cce788
5 files changed
+14 -13

No files matched your search

+4 -10
View File
@@ -126,6 +126,7 @@ import {
} from "@/repositories/index.js";
import { ILogger } from "@/utils/logger.js";
import TimescaleDB from "@/db/TimescaleDB.js";
import { AppError } from "@/utils/AppError.js";
export type InitializedServices = {
settingsService: ISettingsService;
@@ -175,25 +176,18 @@ export const initializeServices = async ({
}): Promise<InitializedServices> => {
// Create DB
let dbType = "mongodb";
const connectionString = envSettings.dbConnectionString;
if (connectionString.startsWith("mongodb")) {
dbType = "mongodb";
} else if (connectionString.startsWith("postgresql")) {
dbType = "postgresql";
}
const dbType = envSettings.dbType;
let db: IDb | null = null;
if (dbType === "mongodb") {
db = new MongoDB(logger, envSettings);
} else if (dbType === "postgresql") {
} else if (dbType === "timescaledb") {
db = new TimescaleDB(logger, envSettings);
}
if (!db) {
throw new Error("Unsupported database type");
throw new AppError({ message: "Unsupported database type", status: 500 });
}
await db.connect();
+2 -2
View File
@@ -1,8 +1,8 @@
import { initializeServices } from "./config/services.js";
import { initializeControllers } from "./config/controllers.js";
import { createApp } from "./app.js";
import { initShutdownListener } from "./shutdown.js";
import { validateEnv } from "./validation/envValidation.js";
import { initShutdownListener } from "@/shutdown.js";
import { validateEnv } from "@/validation/envValidation.js";
import { fileURLToPath } from "url";
import path from "path";
import fs from "fs";
+3 -1
View File
@@ -1,5 +1,5 @@
import { ISettingsRepository } from "@/repositories/index.js";
import { Settings, SettingsUpdate } from "@/types/index.js";
import { type DbType, Settings, SettingsUpdate } from "@/types/index.js";
import { AppError } from "@/utils/AppError.js";
import { ValidatedEnv } from "@/validation/envValidation.js";
import type { StringValue } from "ms";
@@ -12,6 +12,7 @@ export type EnvConfig = {
logLevel: string;
clientHost: string;
dbConnectionString: string;
dbType: DbType;
};
export interface ISettingsService {
@@ -35,6 +36,7 @@ export class SettingsService implements ISettingsService {
logLevel: env.LOG_LEVEL,
clientHost: env.CLIENT_HOST,
dbConnectionString: env.DB_CONNECTION_STRING,
dbType: env.DB_TYPE,
};
}
+3
View File
@@ -1,3 +1,6 @@
export const DbTypes = ["timescaledb", "mongodb"] as const;
export type DbType = (typeof DbTypes)[number];
export interface SettingsThresholds {
cpu?: number;
memory?: number;
+2
View File
@@ -1,4 +1,5 @@
import { z } from "zod";
import { DbTypes } from "@/types/settings.js";
const envSchema = z.object({
// Server Configuration
@@ -8,6 +9,7 @@ const envSchema = z.object({
// Database
DB_CONNECTION_STRING: z.string().min(1, "Database connection string is required"),
DB_TYPE: z.enum(DbTypes).default("mongodb"),
// JWT Authentication
JWT_SECRET: z.string().min(1, "JWT_SECRET is required"),