diff --git a/front/src/env.d.ts b/front/src/env.d.ts index f964fe0..1515a63 100644 --- a/front/src/env.d.ts +++ b/front/src/env.d.ts @@ -1 +1,22 @@ +/// /// + + +export interface ImportMetaEnv { + NODE_ENV: string + APP_URL: string + + POCKETBASEURL: string +} + +interface ImportMeta { + readonly env: ImportMetaEnv +} + + +declare namespace App { + /** + * Middlewares variables + */ + interface Locals {} +} diff --git a/front/src/libs/Env.ts b/front/src/libs/Env.ts new file mode 100644 index 0000000..1521696 --- /dev/null +++ b/front/src/libs/Env.ts @@ -0,0 +1,17 @@ +import type { ImportMetaEnv } from 'env' + +/** + * Get the environment variable + * + * @param key the env variable key + * @param defaultValue a default value if applicable + * @returns the environment value or undefined if not found + */ +export function getEnv(key: keyof ImportMetaEnv, defaultValue: string): string +export function getEnv(key: keyof ImportMetaEnv, defaultValue?: string | undefined): string | undefined +export function getEnv(key: keyof ImportMetaEnv, defaultValue?: string | undefined): string | undefined { + // get the env variable through Astro > NodeJS > input + const res = import.meta.env[key] ?? process.env[key] ?? defaultValue + + return res ?? undefined +}