Build environment variables
aaronclaes
PROOP

7 months ago

Is there a way to detect in code if a project is building?

I use payload CMS which needs to access the database during build time. This currently prevents me from using the private network to access my database.

I would want to do something like this, but I am not sure if that information is available, or if there is another way to do this?

db: mongooseAdapter({
    url: isBuild
      ? process.env.BUILD_DATABASE_URI || '' // Use public URI here
      : process.env.DATABASE_URI || '', // Use private URI here
  }),
Solved

5 Replies

aaronclaes
PROOP

7 months ago

N/A


mjablonski
PRO

7 months ago

Maybe the simplest solution might work for you?

How about adding an additional enviornment variable to your npm-build-task?

"build": "cross-env BUILD=true NODE_OPTIONS=--no-deprecation next build"

And then check this via process.env:

db: mongooseAdapter({

url: process.env.BUILD

? process.env.BUILD_DATABASE_URI || '' // Use public URI here

: process.env.DATABASE_URI || '', // Use private URI here

})


aaronclaes
PROOP

7 months ago

That worked, thanks!


brody
EMPLOYEE

7 months ago

thank you very much Maik!!


brody
EMPLOYEE

7 months ago

!s


Status changed to Solved brody 7 months ago


Loading...