Last active
August 15, 2024 09:48
-
-
Save matthewmorek/55292c134957eaeebec2037e7d989223 to your computer and use it in GitHub Desktop.
Handling BASE_URLs in Vercel env
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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