32 lines
974 B
TypeScript
32 lines
974 B
TypeScript
/* eslint-disable import/no-anonymous-default-export */
|
|
// Homepagesection / whatsNewBanner
|
|
|
|
import { apiVersion, dataset, projectId, useCdn } from 'lib/sanity.api'
|
|
import { createClient } from 'next-sanity'
|
|
|
|
const client = projectId
|
|
? createClient({
|
|
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
|
|
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,
|
|
apiVersion: process.env.NEXT_PUBLIC_SANITY_API_VERSION,
|
|
useCdn: true,
|
|
token: process.env.SANITY_API_READ_TOKEN,
|
|
})
|
|
: null
|
|
|
|
export default async (req, res) => {
|
|
const query = `*[_type == "whatsNewBanner" && _id == "38b5c7df-3e08-435a-bf9a-8a3ffd9d7b99"]{
|
|
"mainImage": mainimage.asset -> url,
|
|
"alt": mainimage.alt,
|
|
...,
|
|
} `
|
|
|
|
try {
|
|
const data = await client.fetch(query)
|
|
res.status(200).json(data)
|
|
} catch (error) {
|
|
console.error('Error fetching Sanity data:', error)
|
|
res.status(500).json({ error: 'Error fetching Sanity data' })
|
|
}
|
|
}
|