#Workaround for runtime env

1 messages · Page 1 of 1 (latest)

summer terrace
#

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?

sturdy reefBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

digital thunder
summer terrace
digital thunder
#

this is the only package I know

#

though the last released version was 10 months ago, their repo was last updated 2 months ago

#

maybe you could clone and build the package yourself

summer terrace