Skip to content

Best way to achieve a dynamic serverURL using environment variables? #31

Answered by jmikrut
joshhills asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @joshhills

Take a look at this package:

https://github.com/payloadcms/nextjs-custom-server

It's not quite done yet as of this writing (will be coming out later this week) and it's meant to showcase how Payload can be combined directly with a custom NextJS server which is likely different than your use case, but it shows an example for how you can use an environment variable as your serverURL.

There are two things to note here:

  1. You can use dotenv in your Payload config! This will make sure that server-side code has access to your environment variables. But, it won't have any effect in the browser as there is no process in the browser. As you mentioned, we mock dotenv for the browser…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@joshhills
Comment options

Answer selected by jmikrut
Comment options

You must be logged in to vote
3 replies
@jmikrut
Comment options

@joshhills
Comment options

@zaunermax
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants