|
2 | 2 | export const fetcher = (...args) => fetch(...args).then((res) => res.json()) // eslint-disable-line no-undef
|
3 | 3 |
|
4 | 4 | /**
|
5 |
| - * On scroll, add or remove a "shrink" class. |
| 5 | + * Retrieve environment-specific var. |
6 | 6 | *
|
7 |
| - * @param {object} el The header element. |
| 7 | + * @param {string} varName Environment variable. |
| 8 | + * @param {bool} isPublic Whether var is public. |
| 9 | + * @return {string} Env var value. |
8 | 10 | */
|
9 |
| -export function shrinkHeader(el) { |
10 |
| - /* eslint-disable */ |
11 |
| - window.addEventListener('scroll', () => { |
12 |
| - if (window.scrollY > 30) { |
13 |
| - el.current.classList.add('shrink') |
14 |
| - } else { |
15 |
| - el.current.classList.remove('shrink') |
16 |
| - } |
17 |
| - }) |
18 |
| - /* eslint-enable */ |
| 11 | +export function getEnvVar(varName, isPublic = false) { |
| 12 | + const prefix = isPublic ? 'NEXT_PUBLIC_' : '' |
| 13 | + |
| 14 | + // If var missing or currently in Vercel "dev" (local), use local settings. |
| 15 | + if (!process.env.VERCEL_ENV || 'development' === process.env.VERCEL_ENV) { |
| 16 | + return process.env[`${prefix}LOCAL_${varName}`] |
| 17 | + } |
| 18 | + |
| 19 | + // Prod / main / default. |
| 20 | + if ( |
| 21 | + 'production' === process.env.VERCEL_ENV || |
| 22 | + 'preview' !== process.env.VERCEL_ENV |
| 23 | + ) { |
| 24 | + return process.env[`${prefix}PROD_${varName}`] |
| 25 | + } |
| 26 | + |
| 27 | + // Switch between staging and develop in Vercel "preview" env. |
| 28 | + switch (process.env.VERCEL_GITHUB_COMMIT_REF) { |
| 29 | + case 'staging': |
| 30 | + return process.env[`${prefix}STAGING_${varName}`] |
| 31 | + case 'develop': |
| 32 | + default: |
| 33 | + return process.env[`${prefix}DEV_${varName}`] |
| 34 | + } |
19 | 35 | }
|
0 commit comments