import { NextResponse } from "next/server"; import type { NextRequest } from "next/server"; const disabled = () => NextResponse.json( { error: "UploadThing is not configured. Add UPLOADTHING_SECRET to .env or use STORAGE_PROVIDER=local.", }, { status: 503 } ); // Lazily resolve the real handlers only when the secret is present. // This prevents the UploadThing SDK from throwing at module-load time // when the env var is missing (e.g. STORAGE_PROVIDER=local). async function getHandlers() { if (!process.env.UPLOADTHING_SECRET) return null; const { createRouteHandler } = await import("uploadthing/next"); const { uploadRouter } = await import("@/lib/uploadthing"); return createRouteHandler({ router: uploadRouter }); } export async function GET(req: NextRequest) { const h = await getHandlers(); return h ? h.GET(req) : disabled(); } export async function POST(req: NextRequest) { const h = await getHandlers(); return h ? h.POST(req) : disabled(); }