How to Add custom env
Unanswered
Lazuee posted this in #help-forum
LazueeOP
I want to put gitpod current base url on port
I want it to run once,. not every reload of the web page.
import { $ } from "zx";
if (process.env?.GITPOD_WORKSPACE_URL && !process.env?.NEXT_PUBLIC_GITPOD_URL)
(process.env as any).NEXT_PUBLIC_GITPOD_URL = (await $`gp url 3000`).stdout;I want it to run once,. not every reload of the web page.
3 Replies
LazueeOP
where can i put it to run it once? and to be able to access it every where?
Persian
My next.config.js file look like this:
module.exports = {
publicRuntimeConfig: {
BACKEND_URL: process.env.BACKEND_URL
}
};
And then in code:
import getConfig from 'next/config';
const { publicRuntimeConfig } = getConfig();
....
return await fetch(
module.exports = {
publicRuntimeConfig: {
BACKEND_URL: process.env.BACKEND_URL
}
};
And then in code:
import getConfig from 'next/config';
const { publicRuntimeConfig } = getConfig();
....
return await fetch(
${publicRuntimeConfig.BACKEND_URL}/xxx....