datocms / gatsby-source-datocms

Official GatsbyJS source plugin to pull content from DatoCMS
MIT License
140 stars 50 forks source link

set previewMode for users if theyre using Gatsby Cloud #157

Closed DanielSLew closed 3 years ago

DanielSLew commented 3 years ago

In Gatsby Cloud, for our new version of Preview we need the user to have previewMode enabled when the user is on a preview and disabled when the user is on a production build. We need to have a mechanism to check if they're currently running in a preview or not. Rather than having the user be responsible for configuring this like so:

{
      resolve: "gatsby-source-datocms",
      options: {
        apiToken: process.env.DATO_API_TOKEN,
        environment: process.env.DATO_ENVIRONMENT,
        previewMode: process.env.GATSBY_IS_PREVIEW,
      },
    },

We want to be able to rollout the new changes without asking the users to have to take action and alter their gatsby-config file for the fix to work.

We will check to see if the GATSBY_IS_PREVIEW env variable is present, which means they're on Gatsby Cloud hosting, and then check its value to determine if we're looking at a preview or not.

stefanoverna commented 3 years ago

Makes sense! Thanks @DanielSLew