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

Previewing with Gatsby cloud is not possible. #5

Closed
monachilada opened this issue Nov 13, 2020 · 5 comments
Closed

Previewing with Gatsby cloud is not possible. #5

monachilada opened this issue Nov 13, 2020 · 5 comments

Comments

@monachilada
Copy link
Contributor

Live preview with a self managed development instance works great with the plugin so long as the ENABLE_GATSBY_REFRESH_ENDPOINT .env variable is enabled and the preview URL matches what's been set in the plugin settings.

However, Gatsby Cloud's Preview service works slightly differently. Instead of exposing the __refresh URL to trigger a rebuild of a development site, they instead expect a post request to a randomly generated webhook. This is running on a different domain and so the comparison referenced in the code below will fail.

if ((doPreview || currentlyPreviewing) && (!doPreview || ("$compare" == compareUrl.protocol + '//' + compareUrl.host))) {

Since there is no apparent relation between the webhook URL and the preview URL, there would need to be some other way to identify which preview URL belongs to which webhook. For illustration purposes, a webhook and preview URL might look like this:

URL: https://preview-PROJECT-SLUG.gtsb.io/
Webhook: https://webhook.gatsbyjs.com/hooks/data_source/RANDOM-STRING

Secondly, the webhook doesn't expect __refresh to be appended to the URL, so this code will generate an invalid URL to send the post hook too.

$refreshUrl = StringHelper::removeRight($previewUrl, '/') . '/__refresh';

@andris-sevcenko
Copy link
Contributor

Yeah, I'm on it.

@andris-sevcenko
Copy link
Contributor

I've fixed the whole __refresh saga, however, Live Preview still won't correctly work on Gatsby Cloud. It appears, there's some backend engineering that still needs to be in place. We're working on it :)

@andris-sevcenko
Copy link
Contributor

With the next release of this plugin (soon!) the Gatsby Cloud previews should work.

Going forward, the freshly renamed webhookTarget setting should be the entire webhook target, whether it ends in __refresh or whether it's a Gatsby Cloud webhook. No more guessing by this plugin.

@brandonkelly
Copy link
Member

Gatsby Helper 1.0.0-beta.2 is out now with this change.

@sandren
Copy link

sandren commented Dec 4, 2020

It's working! 😍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants