Last active
August 19, 2021 15:54
-
-
Save backlineint/835b4ef322bedaff108fff3c912c94a1 to your computer and use it in GitHub Desktop.
dotenv dev, test live snippet
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 path = require("path"); | |
const dotenv = require("dotenv"); | |
// Register envars for dev, test, live or local if available | |
switch(process.env.BACKEND_ENV) { | |
case 'dev': | |
dotenv.config({ path: path.resolve(process.cwd(), '.env.dev') }) | |
case 'test': | |
dotenv.config({ path: path.resolve(process.cwd(), '.env.test') }) | |
case 'live': | |
dotenv.config({ path: path.resolve(process.cwd(), '.env.live') }) | |
default: | |
dotenv.config({ path: path.resolve(process.cwd(), '.env.local') }) | |
} | |
const env = process.env.BACKEND_ENV; | |
const site = process.env.BACKEND_SITE; | |
// Use URL from .env if it exists, otherwise fall back on constructing | |
// Pantheon site URL | |
const url = process.env.WPGRAPHQL_URL || `https://${env}-${site}.pantheonsite.io/graphql`; | |
module.exports = { | |
env: { | |
backendUrl: url | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment