From 5d9f494a4183359c7c8cbe88dd22edfbfe9dcb59 Mon Sep 17 00:00:00 2001 From: evlist Date: Fri, 3 Mar 2023 10:18:21 +0100 Subject: [PATCH] Reading conf file --- .gitignore | 2 +- src/routes/api/conf/[token]/index.ts | 4 +++- src/server-only-lib/read-config.ts | 7 +++++++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 src/server-only-lib/read-config.ts diff --git a/.gitignore b/.gitignore index 13f658c..46fd42b 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,4 @@ gitignore Thumbs.db # Conf -./conf/ +conf/ diff --git a/src/routes/api/conf/[token]/index.ts b/src/routes/api/conf/[token]/index.ts index abccdc4..a8817cc 100644 --- a/src/routes/api/conf/[token]/index.ts +++ b/src/routes/api/conf/[token]/index.ts @@ -1,6 +1,8 @@ import { APIEvent, json } from 'solid-start/api'; +import { readConfig } from '~/server-only-lib/read-config'; export async function GET({ params, env }: APIEvent) { - console.log({ caller: 'api/conf GET', params }); + const {credentials} = readConfig(); + console.log({ caller: 'api/conf GET', params, credentials }); return json({ params, env, response: 'OK' }); } diff --git a/src/server-only-lib/read-config.ts b/src/server-only-lib/read-config.ts new file mode 100644 index 0000000..a7daeb1 --- /dev/null +++ b/src/server-only-lib/read-config.ts @@ -0,0 +1,7 @@ +import { readFileSync } from 'node:fs'; + +export const readConfig = () => { + const filePath = 'conf/config.json'; + const fileContent = readFileSync(filePath, { encoding: 'utf-8' }); + return JSON.parse(fileContent); +};