piranha.core icon indicating copy to clipboard operation
piranha.core copied to clipboard

Page preview doesn't seem to work in non-default site

Open nninja94 opened this issue 4 years ago • 9 comments

Hi, I am not sure if this is an issue, or I am doing something wrong so please comment on your thoughts. I have 2 websites, one for English and one for French languages. Preview of pages seems to work in English site, which happened to be default site but it doesn't seem to work in French site.

Here is my configuration: image

Default site hostnames and other settings image

French site hostnames and other settings image

When I preview page in default/English site, it works just fine

image

But when I try to preview same home page in French site, nothing seems to load image

Any advice would be greatly appreciated

By the way, your product is awesome for anyone who doesn't want to give too much control to content editors and site managers, Great Job!!!

nninja94 avatar Aug 04 '20 21:08 nninja94

We have some new helpers for generating absolute urls coming in 8.4. We’ll take a look if these can be used to solve this issue.

tidyui avatar Aug 06 '20 05:08 tidyui

This is not such an easy issue to solve.

How it works today

When you click preview the manager assumes that the client web is running on the same domain as the manager, i.e it resolves the preview URL to current domain/the slug.

How it should work

In order to preview content on different urls the preview url needs to be generated by looking at the hostnames field on the site. This could however cause other issues, like:

  1. You need to have different hostnames for development & production as they usually differ
  2. If the website is on a different domain than the manager the preview won't work as it relies on the cookie from the manager session. This means authentication for accessing the content being previewed needs to be handled differently.

Quick fix

We could probably provide a quick fix by looking if the site has a prefix added to it, i.e hostname/prefix, in this case would could send preview to current domain/prefix/slug, the other fixes will need bigger changes and are best saved for the next major release.

tidyui avatar Aug 11 '20 13:08 tidyui

@nninja94 Btw, I forget to comment on you initial finding, that the English site works. The reason is that preview will run on localhost/manager/page/preview, since this isn't found as a valid hostname for any of the sites it picks the default site.

tidyui avatar Aug 12 '20 13:08 tidyui

As the changes needed to solve this properly isn't included in 9.0 we will have to hold on this issue.

tidyui avatar Dec 22 '20 06:12 tidyui

@tidyui Could this be handled using a query string? We could do pageid=<guid> or I supposed you could do hostname=<hostname>&slug=<slug>. Would this need to be done inside the RoutingMiddleware?

PizzaConsole avatar Apr 08 '22 06:04 PizzaConsole

@PoisnFang Unfortunately no. The problem is that the property hostnames on the site can contain any number of hostnames, which can be a mix of production and development hostnames. Given the current structure there's no way the manager interface can know what hostname to use when creating the preview URL, that's why it currently always uses the hostname of the current request.

We have several open issues on this, but all of them requires breaking changes and database updates.

The simple solution is to just login to the manager interface on the domain you want to preview. For example, if you have two sites site1.com and site2.com. As long as the editor uses site2.com/manager when editing and previewing content for that site everything will work. The problem arises when using site1.com/manager and you want to preview something from site2.com.

Best regards

tidyui avatar Apr 08 '22 19:04 tidyui

@tidyui We can obtain the proper site data in the router using the page guid. I was able to make a couple of quick changes to make this work. Essentially in the iframe I pass in

hostname?draft=true&preview=true&pageid=

Then in the router if the request query has values for preview and pageid then it gets the page by pageid and then get the site by the siteif on the page. With a couple of changes to the GET endpoint for the Singlepage it then resolves without and issue.I am sure there are things that I have not accounted for, but I will fork and add my changes so I can demonstrate the concept.

PizzaConsole avatar Apr 08 '22 23:04 PizzaConsole

The problem is that the property hostnames can contain a comma separated list of hosts, for example production and development. As it’s just a string there’s no way of indicating which host name to use in the environment the application is running.

mid you only have a single host name in the field I can see how you can get it to work.

tidyui avatar Apr 09 '22 04:04 tidyui

The hostname does not matter in this instance because we pull the site data based on the siteid attached to the page. Once I publish the fork it will make more sense.

PizzaConsole avatar Apr 09 '22 04:04 PizzaConsole