graphql.ts24 lines · main
1import { NextApiRequest, NextApiResponse } from 'next'
2
3const CONTENT_API_URL = process.env.NEXT_PUBLIC_CONTENT_API_URL!
4
5export default async function handler(req: NextApiRequest, res: NextApiResponse) {
6 if (req.method !== 'POST') {
7 res.setHeader('Allow', ['POST'])
8 return res.status(405).json({ error: `Method ${req.method} Not Allowed` })
9 }
10
11 try {
12 const response = await fetch(CONTENT_API_URL, {
13 method: 'POST',
14 headers: { 'Content-Type': 'application/json' },
15 body: JSON.stringify(req.body),
16 })
17
18 const data = await response.json()
19 return res.status(response.status).json(data)
20 } catch (error) {
21 console.error('Content API proxy error:', error)
22 return res.status(500).json({ error: 'Failed to reach Content API' })
23 }
24}