Skip to content

Instantly share code, notes, and snippets.

@backlineint
Last active August 19, 2021 15:54
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 backlineint/835b4ef322bedaff108fff3c912c94a1 to your computer and use it in GitHub Desktop.
Save backlineint/835b4ef322bedaff108fff3c912c94a1 to your computer and use it in GitHub Desktop.
dotenv dev, test live snippet
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