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

Strategy for preview implementation #58

Open
ghisleouf opened this issue May 5, 2022 · 0 comments
Open

Strategy for preview implementation #58

ghisleouf opened this issue May 5, 2022 · 0 comments

Comments

@ghisleouf
Copy link

Hello everybody,

I'm back with another question which is much more about getting your advices and best practices for preview setup.

Let'say that I setup a website called www.mysite.com with Contentful and I want to add the preview feature.

What I have in mind is that I want to setup a simple preview passing a query string parameter like ?preview=1 to switch to preview mode. For example, on the homepage https://www.mysite.com/ will switch to preview mode when I add https://www.mysite.com/?preview=1

First question, is it a good idea ?

Now, going deeper in it, I created a service called "Contentful" where I inject the client thanks to dependency injection:

<?php

namespace App\Service;

use Contentful\Delivery\Client\ClientInterface;
use Contentful\Delivery\Query;
use Contentful\Delivery\Resource\Entry;

class Contentful
{


    private ClientInterface $client;

    public function __construct(ClientInterface $client)
    {
        $this->client = $client;
    }
...

Now, I'm a little bit stuck about the way to switch to preview API with my client injected like that.
What I have in mind is :

  • Intercept all the request to my website
  • Check if the query string preview=1 exists
  • Create a factory to inject the client saying to use preview API instead of main API when the query string is there

Is it a good strategy or am I overcomplicating things ?
What is yours ? ( using a subdomain ? )

Thanks for your feedback.

Best.

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

1 participant