Skip to content

Instantly share code, notes, and snippets.

@pugson
Forked from matthewmorek/constants.ts
Created April 13, 2024 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pugson/6861813e789a7fb572cba51def0daa0a to your computer and use it in GitHub Desktop.
Save pugson/6861813e789a7fb572cba51def0daa0a 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