Runtime environment variable for rewrite
Unanswered
Harlequin posted this in #help-forum
HarlequinOP
Hi,
I have a rewrite configuration in
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?
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?
2 Replies
HarlequinOP
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...
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...
HarlequinOP
At least this method does appear to have successfully worked around the issue...