import { NextRequest } from 'next/server' import { getServerSession } from 'next-auth' import { authOptions } from '@/app/api/auth/[...nextauth]/route' export async function POST(req: NextRequest) { try { const session = await getServerSession(authOptions) if (!session) { return new Response(JSON.stringify({ error: 'Unauthorized' }), { status: 401, }) } const data = await req.json() const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/account/create_route/`, { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${session.accessToken}`, }, body: JSON.stringify({ ...data, comment: data.comment || '', }), }) if (!response.ok) { const error = await response.json() return new Response(JSON.stringify(error), { status: response.status }) } const result = await response.json() return new Response(JSON.stringify(result), { status: 200 }) } catch (error) { return new Response(JSON.stringify({ error: 'Internal Server Error' }), { status: 500, }) } }