envs
All checks were successful
Build & Deploy KLZ Cables / build-and-deploy (push) Successful in 3m52s
All checks were successful
Build & Deploy KLZ Cables / build-and-deploy (push) Successful in 3m52s
This commit is contained in:
@@ -2,17 +2,28 @@
|
||||
* Centralized configuration management for the application.
|
||||
* This file defines the schema and provides a type-safe way to access environment variables.
|
||||
*/
|
||||
import dotenv from 'dotenv';
|
||||
import path from 'path';
|
||||
|
||||
// Load .env file in development or if not already loaded
|
||||
if (typeof process !== 'undefined' && process.env.NODE_ENV !== 'production') {
|
||||
dotenv.config({ path: path.resolve(process.cwd(), '.env') });
|
||||
}
|
||||
|
||||
const getEnv = (key: string, defaultValue?: string): string | undefined => {
|
||||
// In the browser, we can only access NEXT_PUBLIC_ variables
|
||||
if (typeof window !== 'undefined') {
|
||||
if (!key.startsWith('NEXT_PUBLIC_')) {
|
||||
return defaultValue;
|
||||
}
|
||||
return (process.env as any)[key] || defaultValue;
|
||||
}
|
||||
|
||||
if (typeof process === 'undefined') return defaultValue;
|
||||
return process.env[key] || defaultValue;
|
||||
if (typeof process === 'undefined') return defaultValue;
|
||||
|
||||
// In Docker/Production, variables are in process.env
|
||||
// In local development, they might be in .env
|
||||
const value = process.env[key];
|
||||
|
||||
if (value !== undefined && value !== '') {
|
||||
return value;
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
};
|
||||
|
||||
export const config = {
|
||||
|
||||
Reference in New Issue
Block a user