Skip to content
Discussion options

You must be logged in to vote

This should be solved with the App Router. We can safely read environment variables on the server during dynamic rendering. This allows you to use a singular Docker image that can be promoted through multiple environments with different values. So you could use whatever environment you want. Build once, run anywhere.

import { unstable_noStore as noStore } from 'next/cache';
 
export default function Component() {
  noStore(); // Opt-into dynamic rendering
  // This value will be evaluated at runtime
  const value = process.env.MY_VALUE
  ...
}

You can also opt into dynamic rendering in other ways, like using cookies or headers, but this is an example.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by leerob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants