InfraHub
1import type { NextApiRequest, NextApiResponse } from 'next'
2
3export default async function handler(req: NextApiRequest, res: NextApiResponse) {
4const backendUrl = process.env.BACKEND_URL // URL вашего Laravel бэкенда
5
6if (req.method === 'GET') {
7const response = await fetch(`${backendUrl}/api/posts`)
8const data = await response.json()
9res.status(200).json(data)
10} else if (req.method === 'POST') {
11const response = await fetch(`${backendUrl}/api/posts`, {
12method: 'POST',
13headers: {
14'Content-Type': 'application/json',
15},
16body: JSON.stringify(req.body),
17})
18const data = await response.json()
19res.status(201).json(data)
20} else {
21res.setHeader('Allow', ['GET', 'POST'])
22res.status(405).end(`Method ${req.method} Not Allowed`)
23}
24}