fix: set search params in page
This commit is contained in:
@@ -10,38 +10,34 @@ import ContentstackLivePreview from "@contentstack/live-preview-utils";
|
||||
export async function previewRequest<T>(
|
||||
query: string | DocumentNode,
|
||||
variables?: {}
|
||||
): Promise<Data<T> | null> {
|
||||
const hash = ContentstackLivePreview.hash;
|
||||
): Promise<Data<T>> {
|
||||
try {
|
||||
const hash = ContentstackLivePreview.hash;
|
||||
|
||||
if (!hash) {
|
||||
return null;
|
||||
}
|
||||
if (!hash) {
|
||||
throw new Error("No hash received");
|
||||
}
|
||||
|
||||
if (!env.CMS_PREVIEW_URL || !env.CMS_PREVIEW_TOKEN) {
|
||||
throw new Error("No preview URL");
|
||||
}
|
||||
const headers = new Headers();
|
||||
if (!env.CMS_PREVIEW_URL || !env.CMS_PREVIEW_TOKEN) {
|
||||
throw new Error("No preview URL or token");
|
||||
}
|
||||
|
||||
headers.append("access_token", env.CMS_ACCESS_TOKEN);
|
||||
headers.append("Content-Type", "application/json");
|
||||
headers.append("preview_token", env.CMS_PREVIEW_TOKEN);
|
||||
headers.append("live_preview", hash);
|
||||
const headers = new Headers({
|
||||
access_token: env.CMS_ACCESS_TOKEN,
|
||||
preview_token: env.CMS_PREVIEW_TOKEN,
|
||||
live_preview: hash,
|
||||
});
|
||||
|
||||
const response = await fetch(env.CMS_PREVIEW_URL, {
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify({
|
||||
query,
|
||||
const response = await graphqlRequest<T>({
|
||||
document: query,
|
||||
requestHeaders: headers,
|
||||
url: env.CMS_PREVIEW_URL,
|
||||
variables,
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
console.log(response);
|
||||
throw new Error("Cound not fetch preview content");
|
||||
return { data: response };
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw new Error("Something went wrong");
|
||||
}
|
||||
|
||||
const { data } = await response.json();
|
||||
|
||||
return data as Data<T>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user