Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default function RootLayout({
className={`${geistSans.variable} ${geistMono.variable} bg-gray-50 text-gray-900 antialiased transition-colors duration-300 dark:bg-neutral-950 dark:text-gray-100`}
>
{children}
{process.env.NODE_ENV === 'production' && <Analytics />}
{process.env.VERCEL === '1' && <Analytics />}
</body>
</html>
);
Expand Down
20 changes: 18 additions & 2 deletions frontend/lib/env/server-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,30 @@ type NetlifyEnv = {
get?: (key: string) => string | undefined;
};

type NetlifyRuntime = {
env?: NetlifyEnv;
};

declare const Netlify: NetlifyRuntime | undefined;

function getNetlifyRuntime(): NetlifyRuntime | undefined {
const fromGlobalThis = (globalThis as { Netlify?: NetlifyRuntime }).Netlify;
if (fromGlobalThis) return fromGlobalThis;

if (typeof Netlify !== 'undefined') return Netlify;

return undefined;
}

function readFromNetlifyEnv(key: string): string | undefined {
const maybeNetlify = (globalThis as { Netlify?: { env?: NetlifyEnv } }).Netlify;
const value = maybeNetlify?.env?.get?.(key);
const runtime = getNetlifyRuntime();
const value = runtime?.env?.get?.(key);
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
}

export function readServerEnv(key: string): string | undefined {
const fromProcess = process.env[key]?.trim();
if (fromProcess) return fromProcess;

return readFromNetlifyEnv(key);
}
Loading