Ok so, i have a container that compiles the application which is then distributed to different servers, and i have to set NEXT_PUBLIC_* variables at runtime.
This does not seem to be possible, as a workaround i was thinking something like this:
environment.tsx
"use client"
export const ENV = {};
export function Environment({ env }: { env: Record<string, string> }) {
Object.assign(env, ENV);
return null;
}
layout.tsx
export default function Layout() {
return <html>
<body>
<Environment
env={{
APP_URL: process.env.APP_URL!,
}}
/>
</body>
</html>;
}
So i can then use ENV.VAR_NAME in my application.
Would this work? are there better options?