mirror of
https://github.com/documenso/documenso.git
synced 2025-11-15 09:12:02 +10:00
feat: migrate nextjs to rr7
This commit is contained in:
20
packages/lib/utils/env.ts
Normal file
20
packages/lib/utils/env.ts
Normal file
@ -0,0 +1,20 @@
|
||||
/// <reference types="@documenso/tsconfig/process-env.d.ts" />
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
__ENV__?: Record<string, string | undefined>;
|
||||
}
|
||||
}
|
||||
|
||||
type EnvironmentVariable = keyof NodeJS.ProcessEnv;
|
||||
|
||||
export const env = (variable: EnvironmentVariable | (string & object)): string | undefined => {
|
||||
if (typeof window !== 'undefined' && typeof window.__ENV__ === 'object') {
|
||||
return window.__ENV__[variable];
|
||||
}
|
||||
|
||||
return typeof process !== 'undefined' ? process?.env?.[variable] : undefined;
|
||||
};
|
||||
|
||||
export const createPublicEnv = () =>
|
||||
Object.fromEntries(Object.entries(process.env).filter(([key]) => key.startsWith('NEXT_PUBLIC_')));
|
||||
Reference in New Issue
Block a user