diff --git a/config.js b/config.js index edabbd85..f223550f 100755 --- a/config.js +++ b/config.js @@ -13,7 +13,7 @@ const config = { }, live_preview: { enable: false, - host: 'api.contentstack.io' + host: 'rest-preview.contentstack.com' } }; diff --git a/index.d.ts b/index.d.ts index 4e709118..c93dca39 100644 --- a/index.d.ts +++ b/index.d.ts @@ -74,7 +74,8 @@ export interface ContentTypeCollection { export interface LivePreview { host: string - management_token: string + preview_token?: string + management_token?: string enable: boolean } diff --git a/src/core/lib/utils.js b/src/core/lib/utils.js index 7714e358..5fe22827 100755 --- a/src/core/lib/utils.js +++ b/src/core/lib/utils.js @@ -242,7 +242,7 @@ export function sendRequest(queryObject, options) { if(queryObject.requestParams.headers['access_token']) delete queryObject.requestParams.headers['access_token']; - queryObject.requestParams.headers['authorization'] = queryObject.live_preview.management_token + queryObject.requestParams.headers['authorization'] = queryObject.live_preview.preview_token || queryObject.live_preview.management_token; } else if(queryObject.live_preview.live_preview) { cachePolicy = 1; // cache then network } @@ -472,7 +472,8 @@ function generateReferenceMap (references) { async function updateLivePreviewReferenceEntry(referenceMap, entry, stack, options, handlerOptions) { const {live_preview:livePreview, requestParams} = stack; - const { content_type_uid: livePreviewContentTypeUid, management_token } = livePreview; + const { content_type_uid: livePreviewContentTypeUid, preview_token } = + livePreview; async function findReferenceAndFetchEntry(referenceMap, entry, setReference) { @@ -509,7 +510,7 @@ async function updateLivePreviewReferenceEntry(referenceMap, entry, stack, optio stack.requestParams.method = "GET" delete stack.requestParams.headers.access_token - stack.requestParams.headers.authorization = management_token + stack.requestParams.headers.authorization = preview_token; const data = await Request(stack, options); data.entry._content_type_uid = livePreviewContentTypeUid;