danestves / strapi-plugin-preview-content

A plugin for Strapi Headless CMS that provides content preview to integrate with any frontend
MIT License
64 stars 27 forks source link

Strapi v.3.6.5 - draft content not found #33

Open thomaslkp123 opened 2 years ago

thomaslkp123 commented 2 years ago

Hi - I'm from a backend development background - so this issue is possibly due to lacking javascript knowledge.

Having installed the preview plugin - this works for cloning, and getting published content - via the preview API using a url like this: /preview-content/custom-pages/2

However - for draft content - we get a 404 and the message: "Preview not found for given content type and Id".

Trying to debug the plugin - I can see that that line 131 in preview.js is returning null: image

However I am unable to identify why this is.

Any help much appreciated!

thomaslkp123 commented 2 years ago

hi - resolved this by creating a custom controller endpoint - and then in the \node_modules\strapi\lib\core-api\service\index.js - I added method:

const getFetchParamsPreview = (params = {}) => {
  return {
    _publicationState: DP_PUB_STATE_PREVIEW,
    ...params,
    _limit: getLimitParam(params),
  };
};

And in \node_modules\strapi\lib\core-api\service\collection-type.js

findOnePreview(params, populate) {
      return strapi.entityService.findOne(
        { params: getFetchParamsPreview(params), populate },
        { model: modelName }
      );
    },    

This can probably be done in a better way ... but us this something that is missing in v3.6.5 in order for the preview plugin to work - ?