Read .env variables in deployment

default discord avatar
Step
2 months ago
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 🍣
    2 months ago

    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
    iamlinkus
    2 months ago

    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
    Payload Team
    last month

    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.

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

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