Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document ENABLE_GATSBY_REFRESH_ENDPOINT #10328

Closed
m-allanson opened this issue Dec 6, 2018 · 4 comments
Closed

Document ENABLE_GATSBY_REFRESH_ENDPOINT #10328

m-allanson opened this issue Dec 6, 2018 · 4 comments
Labels
help wanted Issue with a clear description that the community can help with. type: documentation An issue or pull request for improving or updating Gatsby's documentation
Projects

Comments

@m-allanson
Copy link
Contributor

m-allanson commented Dec 6, 2018

Summary

Setting an env var ENABLE_GATSBY_REFRESH_ENDPOINT=true while running gatsby develop will configure the develop server to re-source data when it receives a POST request to /__refresh.

This is a really useful feature when working with content while developing your site. The only documentation for this at the moment lives in PR and issue comments. This information should live in the docs of gatsbyjs.org.

Basic example

Useful info available from:

Implementation:

app.post(`/__refresh`, (req, res) => {
const enableRefresh = process.env.ENABLE_GATSBY_REFRESH_ENDPOINT
const refreshToken = process.env.GATSBY_REFRESH_TOKEN
const authorizedRefresh =
!refreshToken || req.headers.authorization === refreshToken
if (enableRefresh && authorizedRefresh) {
console.log(`Refreshing source data`)
sourceNodes()
}
res.end()
})

Possibly in other issues / PRs in this repo.

Motivation

This feature is too useful to remain undocumented 😄

@m-allanson m-allanson added help wanted Issue with a clear description that the community can help with. type: documentation An issue or pull request for improving or updating Gatsby's documentation labels Dec 6, 2018
rfbotto added a commit that referenced this issue Dec 9, 2018
calcsam pushed a commit that referenced this issue Jan 5, 2019
<!--
  Have any questions? Check out the contributing docs at https://gatsby.app/contribute, or
  ask in this Pull Request and a Gatsby maintainer will be happy to help :)
-->

## Description

I added a cURL example for the refresh endpoint e.g. http://localhost:8000/__refresh.

## Related Issues

Related to #10328.
@m-allanson m-allanson added this to Done in OSS Roadmap Jan 9, 2019
gpetrioli pushed a commit to gpetrioli/gatsby that referenced this issue Jan 22, 2019
…10829)

<!--
  Have any questions? Check out the contributing docs at https://gatsby.app/contribute, or
  ask in this Pull Request and a Gatsby maintainer will be happy to help :)
-->

## Description

I added a cURL example for the refresh endpoint e.g. http://localhost:8000/__refresh.

## Related Issues

Related to gatsbyjs#10328.
@RichardBronosky
Copy link

RichardBronosky commented Mar 31, 2019

This ticket and https://github.com/gatsbyjs/gatsby/pull/10366/commits and https://github.com/gatsbyjs/gatsby/projects/2 are still the top Google hits. I have found https://www.gatsbyjs.org/docs/environment-variables/#reserved-environment-variables by reading the related commits. The helped me realize that the reason it seemed to not be working is that I need to POST to it rather than hit it with a browser.

@drake-smith
Copy link

drake-smith commented Apr 15, 2019

I understand how this refresh token is working and have tried it out on my local machine using localhost. However, I wonder how this can be implemented into a preview system for a non-developer, like a client that needs to preview content before publishing. Especially on Contentful, to set up the POST webhook, I need a non-localhost URL. I could use ngrok, but again, that only works in a limited scope, and wouldn't be a permanent and publicly-accessible URL for others to use.

@RichardBronosky
Copy link

@drake-smith You can pass --host=0.0.0.0 to develop to get it to listen on non-local interfaces.

@Charlesdoiron
Copy link

Hi @drake-smith i really need the same online preview for my gatsby contentfull website.
Do you find something ?

thanks a lot !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issue with a clear description that the community can help with. type: documentation An issue or pull request for improving or updating Gatsby's documentation
Projects
No open projects
OSS Roadmap
  
Done
Development

No branches or pull requests

5 participants