From b66178c7ac61b8b1c8dd9af5b647e4878f6c5681 Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Tue, 9 Jan 2024 10:38:32 -0500 Subject: [PATCH] fix: move postgres connection env var to envConfig --- envConfig.js | 8 ++++++++ models/db.mjs | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/envConfig.js b/envConfig.js index 6ce6145d..ea49f7cc 100644 --- a/envConfig.js +++ b/envConfig.js @@ -10,6 +10,12 @@ const getPrefixedEnvVar = (varName, defaultValue = undefined) => { return explicitValue ?? defaultValue; }; +// Database ============================================================================================================ + +// - Postgres connection URI +const PG_CONNECTION = getPrefixedEnvVar( + "PG_CONNECTION", "postgresql://postgres@localhost:5432/postgres"); + // Paths and data locations ============================================================================================ // - This is the application data directory @@ -80,6 +86,8 @@ const PLOT_MANHATTAN_BIN_SIZE = parseInt(getPrefixedEnvVar("MANHATTAN_BIN_SIZE", // Export ============================================================================================================== module.exports = { + // Database + PG_CONNECTION, // Paths and data locations DATA_DIR, ABOUT_MD_PATH, diff --git a/models/db.mjs b/models/db.mjs index c9b5175f..428b8600 100644 --- a/models/db.mjs +++ b/models/db.mjs @@ -1,9 +1,10 @@ -import fs from "fs"; - +import fs from "node:fs"; import pg from "pg"; +import envConfig from "../envConfig.js"; + const pool = new pg.Pool({ - connectionString: process.env.VARWIG_PG_CONNECTION ?? undefined, + connectionString: envConfig.PG_CONNECTION ?? undefined, }); export const ready = new Promise((resolve, reject) => {