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:
parent
a37c9810bf
commit
254de893d6
3 changed files with 27 additions and 4 deletions
|
@ -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>
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
1
apps/client/public/__appenv.js
Normal file
1
apps/client/public/__appenv.js
Normal file
|
@ -0,0 +1 @@
|
|||
window.__appenv = {}
|
Loading…
Add table
Add a link
Reference in a new issue