Last active
January 28, 2020 02:43
-
-
Save cpv123/454600f5f7a2c139eb9dd6e3c467d51a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// gatsby-node.js file | |
const axios = require('axios') | |
require('dotenv').config({ | |
path: `.env.${process.env.NODE_ENV}`, // this dotenv config gives access to process.env object | |
}) | |
const getCoffeeShops = async () => { | |
const shops = await axios.get(process.env.GATSBY_COFFEE_SHOPS_URL) | |
return shops.data.Items | |
} | |
exports.onCreatePage = async ({ page, actions }) => { | |
if (page.path === '/coffee' || page.path === '/coffee/') { | |
const { createPage, deletePage } = actions | |
deletePage(page) | |
const coffeeShops = await getCoffeeShops() | |
createPage({ | |
...page, | |
context: { | |
...page.context, | |
coffeeShops, | |
}, | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment