poprawki po crashu
This commit is contained in:
28
utils/envUtils.ts
Normal file
28
utils/envUtils.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
/**
|
||||
* Safely retrieves environment variables in both Vite (browser) and Node environments.
|
||||
* Prevents "ReferenceError: process is not defined" crashes in production builds.
|
||||
*/
|
||||
export const getEnvVar = (key: string): string => {
|
||||
// 1. Try Vite / Modern Browser approach (import.meta.env)
|
||||
try {
|
||||
// @ts-ignore
|
||||
if (typeof import.meta !== 'undefined' && import.meta.env && import.meta.env[key]) {
|
||||
// @ts-ignore
|
||||
return import.meta.env[key];
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore errors if import.meta is not supported
|
||||
}
|
||||
|
||||
// 2. Try Node / Webpack / Polyfilled approach (process.env)
|
||||
try {
|
||||
if (typeof process !== 'undefined' && process.env && process.env[key]) {
|
||||
return process.env[key] || '';
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore errors if process is not defined
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
Reference in New Issue
Block a user