Skip to content

Instantly share code, notes, and snippets.

@matthewmorek
Last active August 15, 2024 09:48
Show Gist options
  • 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