#Runtime environment variable for rewrite

1 messages · Page 1 of 1 (latest)

autumn hearth
#

Hi,

I have a rewrite configuration in next.config.ts in order to proxy some API requests:

const nextConfig = {
    output: "standalone",
    async rewrites() {
        const base = process.env.EGD_API_BASE_URL;
        if (!base) {
            console.warn(
                "EGD_API_BASE_URL is not set at build time; no /api rewrite will be emitted.",
            );
            return [];
        }
        return [
            {
                source: "/api/:path*",
                destination: `${base}/:path*`,
            },
        ];
    },
};
export default nextConfig;

I think that what is happening is that it's not picking up the environment variable at runtime (this is built into a Docker container for production).

Am I thinking along the right lines? And if so, is there a way to have the environment variable picked up at runtime?

orchid marshBOT
#

🔎 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)

autumn hearth
#

ChatGPT seems to believe that I'm thinking along the right lines about the cause of this problem - that the environment variable is baked in at build time and hence my issue.

Since this is getting deployed into a Kubernetes cluster, I'm now looking at proxying from within the ingress resource, rather than having the application handle it.

Still open to any advice on this...