fix(lstv2): added in a close function to stop crashing the server

This commit is contained in:
2025-11-30 10:31:27 -06:00
parent f226c5644c
commit 712a6eebdf
4 changed files with 182 additions and 171 deletions

View File

@@ -13,6 +13,7 @@ import type { Settings } from "../../../../types/settings.js";
import { createLog } from "../../../logger/logger.js";
export let serverSettings: Settings[] = [];
const dbUrl = String(process.env.DATABASE_URL).replace("lst_db", "lst");
export const getSettings = async () => {
const settingsType = process.env.LST_USE_GO;
createLog(
@@ -21,14 +22,13 @@ export const getSettings = async () => {
"server",
`Settings are being grabbed from the app now`,
);
const client = new Client({
connectionString: dbUrl,
});
//if (settingsType !== "true") {
try {
//serverSettings = (await db.select().from(settings)) as any;
const dbUrl = String(process.env.DATABASE_URL).replace("lst_db", "lst");
const client = new Client({
connectionString: dbUrl,
});
await client.connect();
@@ -38,7 +38,12 @@ export const getSettings = async () => {
serverSettings = s.rows;
} catch (e) {
console.log(e);
createLog(
"error",
"lst",
"server",
`There was an error getting the settings: ${JSON.stringify(e)}`,
);
}
// const { data, error } = (await tryCatch(
@@ -67,9 +72,16 @@ export const getSettings = async () => {
"error",
"lst",
"server",
"There was an error getting the settings",
`There was an error getting the settings: ${JSON.stringify(error)}`,
);
throw new Error("There was an error getting the settings");
//throw new Error("There was an error getting the settings");
} finally {
// ✅ Ensure the connection is always closed
await client
.end()
.catch((e) =>
createLog("error", "lst", "server", `Error closing DB client: ${e}`),
);
}
//}