From 0326e07a3e5a1a5ab7be8e6a95ea0a2ea17e8ce8 Mon Sep 17 00:00:00 2001 From: vliu36 <116984041+vliu36@users.noreply.github.com> Date: Sun, 22 Dec 2024 14:08:41 -0800 Subject: [PATCH] fixed env config --- src/routes/connect.ts | 3 ++- src/routes/serverProps.ts | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/routes/connect.ts b/src/routes/connect.ts index 048145cd..3563e43a 100644 --- a/src/routes/connect.ts +++ b/src/routes/connect.ts @@ -1,7 +1,7 @@ // Connects to MongoDB -// Only need one client instance const { MongoClient, ServerApiVersion } = require("mongodb"); +require("dotenv").config() const USER = process.env.DBUSER; const PSWD = process.env.DBPASS; const HOST = process.env.DBHOST; @@ -32,6 +32,7 @@ async function run() { await client.close(); } } + run().catch(console.dir); export default client; \ No newline at end of file diff --git a/src/routes/serverProps.ts b/src/routes/serverProps.ts index 3a881199..59b32681 100644 --- a/src/routes/serverProps.ts +++ b/src/routes/serverProps.ts @@ -1,7 +1,10 @@ +import client from "./connect"; export const getServerSideProps = (async () => { - const response = await fetch("") - const pageData = await response.json() + await client.connect(); + const response = await client.findOne(); + const pageData = await response.json(); + await client.close(); return { props: {