import { NextResponse } from 'next/server'; import { auth } from '@/auth'; export async function GET(request: Request) { const session = await auth(); if (!session) { return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); } try { const { searchParams } = new URL(request.url); const handle = searchParams.get('handle'); const email = session.user?.email as string | undefined; if (!handle) { return NextResponse.json({ error: '핸들이 필요합니다' }, { status: 400 }); } if (!email) { return NextResponse.json({ error: '세션 이메일을 찾을 수 없습니다' }, { status: 400 }); } const upstream = await fetch('http://localhost:10001/register_channel', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, handle }) }); let data: any = null; const text = await upstream.text(); try { data = text ? JSON.parse(text) : null; } catch { data = { message: text }; } return NextResponse.json(data ?? {}, { status: upstream.status }); } catch (error) { console.error('register_channel 프록시 오류:', error); return NextResponse.json({ error: '업스트림 요청 실패' }, { status: 502 }); } }