-
-
Save pugson/6861813e789a7fb572cba51def0daa0a to your computer and use it in GitHub Desktop.
Handling BASE_URLs in Vercel env
This file contains hidden or 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