meet/app/api/url/route.ts
2024-08-22 11:43:48 +02:00

23 lines
628 B
TypeScript

import { getLiveKitURL } from '../../../lib/server-utils';
import { NextResponse } from 'next/server';
export const runtime = 'edge';
export async function GET(req: Request) {
try {
const url = new URL(req.url);
const searchParams = url.searchParams;
const region = searchParams.get('region');
if (Array.isArray(region)) {
throw Error('provide max one region string');
}
const livekitUrl = getLiveKitURL(region);
return NextResponse.json({ url: livekitUrl });
} catch (error) {
if (error instanceof Error) {
return new NextResponse(error.message, { status: 500 });
}
}
}