Skip to content

Commit

Permalink
Env (#18)
Browse files Browse the repository at this point in the history
* Use environment variables
ryanwiemer authored Aug 1, 2021
1 parent 0cdbbd9 commit dc0c266
Showing 3 changed files with 17 additions and 32 deletions.
11 changes: 0 additions & 11 deletions .contentful.json.sample

This file was deleted.

33 changes: 13 additions & 20 deletions gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
let contentfulConfig

try {
contentfulConfig = require('./.contentful')
} catch (e) {
contentfulConfig = {
production: {
spaceId: process.env.SPACE_ID,
accessToken: process.env.ACCESS_TOKEN,
},
}
} finally {
const { spaceId, accessToken } = contentfulConfig.production
if (!spaceId || !accessToken) {
throw new Error('Contentful space ID and access token need to be provided.')
}
require('dotenv').config({
path: `.env.${process.env.NODE_ENV}`,
})
const contentfulConfig = {
spaceId: process.env.CONTENTFUL_SPACE_ID,
accessToken:
process.env.CONTENTFUL_ACCESS_TOKEN ||
process.env.CONTENTFUL_DELIVERY_TOKEN,
}
if (process.env.CONTENTFUL_HOST) {
contentfulConfig.host = process.env.CONTENTFUL_HOST
contentfulConfig.accessToken = process.env.CONTENTFUL_PREVIEW_ACCESS_TOKEN
}

module.exports = {
@@ -70,10 +66,7 @@ module.exports = {
},
{
resolve: 'gatsby-source-contentful',
options:
process.env.NODE_ENV === 'development'
? contentfulConfig.development
: contentfulConfig.production,
options: contentfulConfig,
},
'gatsby-plugin-netlify',
],
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "rw",
"description": "Ryan Wiemer's online portfolio",
"version": "2.2.0",
"version": "2.2.1",
"author": "Ryan Wiemer <[email protected]>",
"keywords": [
"rw"
@@ -46,6 +46,9 @@
"stylelint-config-styled-components": "^0.1.1",
"stylelint-processor-styled-components": "^1.9.0"
},
"engines": {
"node": ">=10.13.0"
},
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",

0 comments on commit dc0c266

Please sign in to comment.