From a2e78e2e363f47c1b6a81f01defbf23270960f64 Mon Sep 17 00:00:00 2001 From: Valentin Brandl Date: Fri, 16 Aug 2024 15:06:41 +0200 Subject: [PATCH] Fallback for missing environment variable --- src/lib/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/index.ts b/src/lib/index.ts index b3d4e55..1df0551 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -1,6 +1,11 @@ // place files you want to import through the `$lib` alias in this folder. const safePath = (input: string) => input.replace(/\W/g, ''); -export const storagePath: string = process.env.STORAGE_PATH; + +const defaultPath: string = './uploads'; +if (!('STORAGE_PATH' in process.env)) { + console.log(`'STORAGE_PATH' environment variable is not set. Defaulting to ${defaultPath}`); +} +export const storagePath: string = process.env.STORAGE_PATH ?? defaultPath; export default safePath;