Skip to content

Commit

Permalink
Put config in one file
Browse files Browse the repository at this point in the history
  • Loading branch information
jumpalottahigh committed Sep 29, 2018
1 parent bfa46af commit b7e40f2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
8 changes: 8 additions & 0 deletions .config.sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"firebase": {
"key": ""
},
"openWeatherMap": {
"key": ""
}
}
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ public
.intermediate-representation/
.cache/
.contentful.json
.openweathermap.json
.firebaseConfig.json
.config.json
20 changes: 9 additions & 11 deletions gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
let openWeatherConfig
let firebaseConfig
let config

try {
openWeatherConfig = require('./.openWeatherMap')
firebaseConfig = require('./.firebaseConfig')
config = require('./.config')
} catch (e) {
openWeatherConfig = {
config.openWeatherMap = {
key: process.env.GATSBY_OPEN_WEATHER_MAP_KEY,
}

firebaseConfig = {
config.firebase = {
key: process.env.GATSBY_FIREBASE_KEY,
}
} finally {
if (!openWeatherConfig.key) {
if (!config.openWeatherMap.key) {
throw new Error('OpenWeatherMap API key needs to be provided.')
}

if (!firebaseConfig.key) {
throw new Error('OpenWeatherMap API key needs to be provided.')
if (!config.firebase.key) {
throw new Error('Firebase API key needs to be provided.')
}

process.env.GATSBY_OPEN_WEATHER_MAP_KEY = openWeatherConfig.key
process.env.GATSBY_FIREBASE_KEY = firebaseConfig.key
process.env.GATSBY_OPEN_WEATHER_MAP_KEY = config.openWeatherMap.key
process.env.GATSBY_FIREBASE_KEY = config.firebase.key
}

module.exports = {
Expand Down

0 comments on commit b7e40f2

Please sign in to comment.