Skip to content

Instantly share code, notes, and snippets.

@matthewmorek
Last active April 13, 2024 23:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save matthewmorek/55292c134957eaeebec2037e7d989223 to your computer and use it in GitHub Desktop.
Save matthewmorek/55292c134957eaeebec2037e7d989223 to your computer and use it in GitHub Desktop.
Handling BASE_URLs in Vercel env
const { CI, PORT = 3000, VERCEL_ENV, NEXT_PUBLIC_VERCEL_ENV, VERCEL_URL, NEXT_PUBLIC_VERCEL_URL } = process.env;
export const ENVIRONMENT = VERCEL_ENV || NEXT_PUBLIC_VERCEL_ENV;
const baseDomainSource = CI ? VERCEL_URL : NEXT_PUBLIC_VERCEL_URL;
const baseDomain = baseDomainSource;
let BASE_URL: string;
if (ENVIRONMENT === 'preview') {
BASE_URL = `https://${baseDomain}`;
} else if (ENVIRONMENT === 'production') {
BASE_URL = baseDomain!;
} else {
BASE_URL = `http://localhost:${PORT}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment