graphql.ts 782 B

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