Skip to content

Commit b998e7f

Browse files
api roite updated for a function
1 parent dbad2a6 commit b998e7f

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import ContentstackServer from "@/lib/cstack";
2+
3+
export async function POST(request) {
4+
try {
5+
const variantParam = request.headers.get('x-personalize-variants');
6+
const { type, url, locale, references, live_preview } = await request.json();
7+
const res = await ContentstackServer.getElementByUrlWithRefs(type, url, locale, references, live_preview, variantParam);
8+
return Response.json(res || {});
9+
} catch (error) {
10+
console.error(error);
11+
return Response.json({ error: "Failed to fetch data" }, { status: 500 });
12+
}
13+
}

‎src/lib/cstack.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ const ContentstackServer = {
112112
.entry()
113113
.locale(locale ? locale : "en")
114114
.variants(deserializeVariantIds(variantParam))
115+
.includeReference(...references)
115116
.addParams({ "include_applied_variants": "true" })
116117
.query({ "url": { $eq: url } })
117-
.includeReference(...references)
118118
.find()
119119
.then(
120120
function success(data) {

0 commit comments

Comments
 (0)