1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-09 15:35:22 +02:00

feat: Access variables through appenv.sh

This commit is contained in:
Six 2024-01-17 10:31:06 -08:00
parent a37c9810bf
commit 254de893d6
No known key found for this signature in database
GPG key ID: 00148D3869C21E43
3 changed files with 27 additions and 4 deletions

View file

@ -43,6 +43,9 @@ export default function Meta() {
href="https://cdn.jsdelivr.net/npm/remixicon@2.5.0/fonts/remixicon.css"
rel="stylesheet"
/>
{/* <!-- NEXT_PUBLIC_ env variables --> */}
<script src="/__env.js" />
</Head>
)
}

View file

@ -1,8 +1,27 @@
function isBrowser() {
return Boolean(typeof window !== "undefined" && (window.__env || window.__appenv));
}
function env(key: string) {
if (!key.length) {
throw new Error('No env key provided');
}
if (isBrowser()) {
if (key in window.__appenv)
return window.__appenv[key];
return window.__env[key];
}
return process.env[key];
}
const env = {
NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3333',
NEXT_PUBLIC_LD_CLIENT_SIDE_ID: process.env.NEXT_PUBLIC_LD_CLIENT_SIDE_ID || 'REPLACE_THIS',
NEXT_PUBLIC_SENTRY_DSN: process.env.NEXT_PUBLIC_SENTRY_DSN,
NEXT_PUBLIC_SENTRY_ENV: process.env.NEXT_PUBLIC_SENTRY_ENV,
NEXT_PUBLIC_API_URL: env("NEXT_PUBLIC_API_URL") || 'http://localhost:3333',
NEXT_PUBLIC_LD_CLIENT_SIDE_ID: env("process.env.NEXT_PUBLIC_LD_CLIENT_SIDE_ID") || 'REPLACE_THIS',
NEXT_PUBLIC_SENTRY_DSN: env("process.env.NEXT_PUBLIC_SENTRY_DSN"),
NEXT_PUBLIC_SENTRY_ENV: env("process.env.NEXT_PUBLIC_SENTRY_ENV"),
}
export default env

View file

@ -0,0 +1 @@
window.__appenv = {}