diff --git a/server/src/plugins/service-admin-http/index.ts b/server/src/plugins/service-admin-http/index.ts index fa73e2d..9b6d1cf 100644 --- a/server/src/plugins/service-admin-http/index.ts +++ b/server/src/plugins/service-admin-http/index.ts @@ -15,7 +15,7 @@ import { import { H3, serve } from "h3"; import type { Server } from "srvx"; -import { dbConfigSchema, type DbConfig } from "../../shared/db/config.js"; +import type { DbConfig } from "../../shared/db/config.js"; import { initDb } from "../../shared/db/init.js"; import type { Repository } from "../../shared/db/repository.js"; import { initSecrets, type SecretsApi } from "../../shared/secrets.js"; @@ -39,7 +39,20 @@ import { registerCloudRoutes } from "./routes-cloud.js"; const ConfigSchema = av.object( { - db: dbConfigSchema, + db: av.object( + { + driver: av.enum_(["sqlite", "postgres"] as const).default("postgres"), + sqlitePath: av.string().minLength(1).default("/var/lib/betterframe/betterframe.db"), + pgUrl: av.string().default(""), + pgHost: av.string().default("postgres"), + pgPort: av.int().min(1).max(65535).default(5432), + pgDatabase: av.string().default("betterframe"), + pgUser: av.string().default("betterframe"), + pgPassword: av.string().default("betterframe"), + pgPoolMax: av.int().min(1).max(1000).default(10), + }, + { unknownKeys: "strip" }, + ), host: av.string().default("127.0.0.1"), port: av.int().min(1).max(65535).default(18080), // Secrets config (was service-secrets) diff --git a/server/src/plugins/service-api-http/index.ts b/server/src/plugins/service-api-http/index.ts index 39214f4..a8ff423 100644 --- a/server/src/plugins/service-api-http/index.ts +++ b/server/src/plugins/service-api-http/index.ts @@ -15,7 +15,7 @@ import { import { H3, serve, readBody, getRequestHeader, getRouterParam, createError } from "h3"; import type { Server } from "srvx"; -import { dbConfigSchema, type DbConfig } from "../../shared/db/config.js"; +import type { DbConfig } from "../../shared/db/config.js"; import { initDb } from "../../shared/db/init.js"; import type { Repository } from "../../shared/db/repository.js"; import { initSecrets } from "../../shared/secrets.js"; @@ -36,7 +36,20 @@ import type { FirmwareChannel } from "../../shared/types.js"; const ConfigSchema = av.object( { - db: dbConfigSchema, + db: av.object( + { + driver: av.enum_(["sqlite", "postgres"] as const).default("postgres"), + sqlitePath: av.string().minLength(1).default("/var/lib/betterframe/betterframe.db"), + pgUrl: av.string().default(""), + pgHost: av.string().default("postgres"), + pgPort: av.int().min(1).max(65535).default(5432), + pgDatabase: av.string().default("betterframe"), + pgUser: av.string().default("betterframe"), + pgPassword: av.string().default("betterframe"), + pgPoolMax: av.int().min(1).max(1000).default(10), + }, + { unknownKeys: "strip" }, + ), host: av.string().default("127.0.0.1"), port: av.int().min(1).max(65535).default(18081), codeTtlSeconds: av.int().min(60).max(3600).default(600), diff --git a/server/src/plugins/service-coordinator-ws/index.ts b/server/src/plugins/service-coordinator-ws/index.ts index 338f41c..e63645d 100644 --- a/server/src/plugins/service-coordinator-ws/index.ts +++ b/server/src/plugins/service-coordinator-ws/index.ts @@ -23,7 +23,7 @@ import { createServer, type IncomingMessage, type Server as HttpServer } from "n import { randomUUID } from "node:crypto"; import { WebSocketServer, WebSocket } from "ws"; -import { dbConfigSchema, type DbConfig } from "../../shared/db/config.js"; +import type { DbConfig } from "../../shared/db/config.js"; import { initDb } from "../../shared/db/init.js"; import { initSecrets } from "../../shared/secrets.js"; import { createAuth } from "../../shared/auth.js"; @@ -34,7 +34,20 @@ import { initNoderedBridge, type NoderedBridge } from "../../shared/nodered-brid const ConfigSchema = av.object( { - db: dbConfigSchema, + db: av.object( + { + driver: av.enum_(["sqlite", "postgres"] as const).default("postgres"), + sqlitePath: av.string().minLength(1).default("/var/lib/betterframe/betterframe.db"), + pgUrl: av.string().default(""), + pgHost: av.string().default("postgres"), + pgPort: av.int().min(1).max(65535).default(5432), + pgDatabase: av.string().default("betterframe"), + pgUser: av.string().default("betterframe"), + pgPassword: av.string().default("betterframe"), + pgPoolMax: av.int().min(1).max(1000).default(10), + }, + { unknownKeys: "strip" }, + ), host: av.string().default("127.0.0.1"), port: av.int().min(1).max(65535).default(18082), noderedUrl: av.string().minLength(1).default("http://127.0.0.1:1880"),