Read .env variables in deployment

default discord avatar
Steplast year
3

In localhost I have my environment variable

PAYLOAD_PUBLIC_SERVER_URL="http://localhost:3000"

, that is read from

serverURL: process.env.PAYLOAD_PUBLIC_SERVER_URL

The question is, when deploying in production in Cloud Run for example, should this environment variable be assigned, and if so, what url should I assign to this environment variable?

  • default discord avatar
    Alessio 🍣last year

    Yep - very important that you assign this variable. It needs to be the domain you wanna access payload from. So if you set up a custom domain, it would need to be that

  • default discord avatar
    iamlinkuslast year

    Once your service starts for the first time (even though it’s not working without that variable), you’ll see the assigned url in the service info on cloud run. Copy that and just add the url into the environment variables of the service.

  • discord user avatar
    jacobsfletch
    last year

    All good info! I'm also noticing that your environment variable is using quotation marks, these should be removed so that it reads

    PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000

    instead.

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.