Skip to content

Commit 1ee6d1e

Browse files
Merge pull request #431 from DevLoversTeam/sl/feat/db-optimization
Fix Netlify runtime env resolution and Vercel Analytics loading
2 parents 5f84e73 + ee8169d commit 1ee6d1e

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

frontend/app/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default function RootLayout({
8989
className={`${geistSans.variable} ${geistMono.variable} bg-gray-50 text-gray-900 antialiased transition-colors duration-300 dark:bg-neutral-950 dark:text-gray-100`}
9090
>
9191
{children}
92-
{process.env.NODE_ENV === 'production' && <Analytics />}
92+
{process.env.VERCEL === '1' && <Analytics />}
9393
</body>
9494
</html>
9595
);

frontend/lib/env/server-env.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,30 @@ type NetlifyEnv = {
44
get?: (key: string) => string | undefined;
55
};
66

7+
type NetlifyRuntime = {
8+
env?: NetlifyEnv;
9+
};
10+
11+
declare const Netlify: NetlifyRuntime | undefined;
12+
13+
function getNetlifyRuntime(): NetlifyRuntime | undefined {
14+
const fromGlobalThis = (globalThis as { Netlify?: NetlifyRuntime }).Netlify;
15+
if (fromGlobalThis) return fromGlobalThis;
16+
17+
if (typeof Netlify !== 'undefined') return Netlify;
18+
19+
return undefined;
20+
}
21+
722
function readFromNetlifyEnv(key: string): string | undefined {
8-
const maybeNetlify = (globalThis as { Netlify?: { env?: NetlifyEnv } }).Netlify;
9-
const value = maybeNetlify?.env?.get?.(key);
23+
const runtime = getNetlifyRuntime();
24+
const value = runtime?.env?.get?.(key);
1025
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
1126
}
1227

1328
export function readServerEnv(key: string): string | undefined {
1429
const fromProcess = process.env[key]?.trim();
1530
if (fromProcess) return fromProcess;
31+
1632
return readFromNetlifyEnv(key);
1733
}

0 commit comments

Comments
 (0)