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

[4.x]: 404 status when previewing unpublished entries #15016

Open
slemont3 opened this issue May 17, 2024 · 8 comments
Open

[4.x]: 404 status when previewing unpublished entries #15016

slemont3 opened this issue May 17, 2024 · 8 comments
Assignees

Comments

@slemont3
Copy link

What happened?

Description

We are currently migrating an existing Craft website to a Google Cloud App Instance Flex and we are facing an issue with previewing new and unpublished entries. Neither the live editor preview nor the general preview for unpublished pages work and both document requests return a 404 HTTP status.

Steps to reproduce

  1. Go to entries and create a new entry, for example a single page.
  2. Enter content to configured fields
  3. Either save the entry as a draft or as an entry and set the status to disabled.
  4. Now try to open the entry either in preview editor mode or via the view cta.

Expected behavior

The entry's content is loaded and shown in either the live preview or in the regular view in a separate browser tab.

Actual behavior

The page cannot be found and we get a 404 error.

Additionl info

This behaviour only happens on the Google Cloud production or test environment. Locally, it works as expected. Therefore we assumed that there is an issue with the PRIMARY_SITE_URL env variable. Locally, it is set to http://127.0.0.1:8081. On the production and test environments, it is set to the corresponding .appspot.com domain generated by the Google Cloud App engine instance, via which the website is currently reachable. Once the migrated sound will be live with a custom domain, the .appspot.com domain will be replaced by the actual custom domain.

Additionally, we verified whether the preview token is properly saved in the database once it is created, which is the case.

Any help would be highly appreciated!

Craft CMS version

Craft Pro 4.8.9

PHP version

8.3.6

Operating system and version

Linux 6.1.75+

Database type and version

MySQL 8.0.31

Image driver and version

GD 8.3.6

Installed plugins and versions

@angrybrad
Copy link
Member

@slemont3 is it a Cratt-styled 404 response or an nginx/apache styled 404?

Are you accessing the control panel through site.com/admin and the front-end of the site is site.com? Or is control panel access subdomain-based? i.e. cp.site.com and the front-end is site.com

@slemont3
Copy link
Author

Hi @angrybrad , thanks for getting back at this!

It's a Craft-styled 404 response. And the control panel is accessed normally without a subdomain, so for example site.com/admin and the preview url would be: https://site.com/testpage?x-craft-preview=xxx&craft-token=xxxxxxx

Note that the tokenParam config is set to 'craft-token' as we have to use the 'token' query parameter for something else.

@slemont3
Copy link
Author

In addition to the above, we are currently getting the info that our Craft CMS license is invalid since our license is still being used on the live web server we're migrating the website from. Could that affect/limit the preview functionality of unpublished pages?

@Envaya
Copy link

Envaya commented May 22, 2024

Struggling with the very same issue

@brandonkelly
Copy link
Member

@Envaya Also on Google Cloud?

@angrybrad
Copy link
Member

@slemont3

Could that affect/limit the preview functionality of unpublished pages?

Nah - licensing issues won’t affect site functionality.

Any chance we could get some Craft control panel and SSH access to that box to poke around a bit? If so, could you send the details over to support@craftcms.com and reference this issue?

@MilanDeruelle
Copy link

Not sure if this is related, but I am currently also having an issue with previews: My previous projects used a simple entry query with the x-craft-token set. Now, I need to set "drafts: null" in order to get data for the drafts; e.g.

preview: entry(site: $site, uri: $uri, drafts: null) {
          title
          uri
}

Is it possible something did break/change from previous version of 4 to 4.9.5?

@brandonkelly
Copy link
Member

@MilanDeruelle Just tested on 4.9.5 and it worked fine.

I have a preview target set to the URL format graphql-test?entryId={canonicalId}, and a graphql-test.twig template with:

<html>
<head>
  <title>GraphQL Test</title>
</head>
<body>

{% set entryId = craft.app.request.getQueryParam('entryId') %}
{% set token = craft.app.request.getQueryParam('token') %}

<script type="module" async>
  const entryId = {{ entryId|json_encode|raw }};
  const token = {{ token|json_encode|raw }};
  const response = await fetch('/api', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/graphql',
      'X-Craft-Token': token,
    },
    body: `query {
             entry(id: ${entryId}) {
               title
             }
           }`
  });
  const json = await response.json();
  document.write(`<p>${json.data.entry.title}</p>`);
</script>

</body>
</html>

This is using the public schema, which I’ve configured to include all entry queries, but not drafts, revisions, or non-live elements.

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

No branches or pull requests

5 participants