Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

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 dedicated engineering support directly from the Payload team..