feat: runtime env

Support runtime environment variables using server components.

This will mean docker images can change env vars for runtime as required.
This commit is contained in:
Mythie
2023-11-12 13:10:30 +11:00
parent aec0d2ae97
commit 1cd60e1abb
29 changed files with 254 additions and 70 deletions

View File

@@ -0,0 +1,20 @@
import { useRuntimeEnv } from './runtime-env/client';
/* eslint-disable turbo/no-undeclared-env-vars */
export const useBaseUrl = () => {
const { NEXT_PUBLIC_WEBAPP_URL } = useRuntimeEnv();
if (typeof window !== 'undefined') {
return '';
}
if (process.env.VERCEL_URL) {
return `https://${process.env.VERCEL_URL}`;
}
if (NEXT_PUBLIC_WEBAPP_URL) {
return NEXT_PUBLIC_WEBAPP_URL;
}
return `http://localhost:${process.env.PORT ?? 3000}`;
};