Introduce `serverLogger` utility based on pino for consistent, structured logging across all server and API modules. Replace direct console logging with `serverLogger` and add request-scoped logging helpers. Update environment variable handling, documentation, and deployment guides to reflect new logging configuration (`LOG_FORMAT`, `LOG_LEVEL`, `COMPUTE_LOG_LEVEL`). Enforce no-console in server code via ESLint and add pino/pino-pretty dependencies. This change standardizes log output, improves observability, and prepares the codebase for ingestion by log platforms.
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { auth } from '@/lib/server/auth/auth';
|
|
import { isAuthEnabled } from '@/lib/server/auth/config';
|
|
import { listAdminProviders, toPublic } from '@/lib/server/admin/providers';
|
|
import { serverLogger } from '@/lib/server/logger';
|
|
|
|
export const dynamic = 'force-dynamic';
|
|
|
|
/**
|
|
* Public list of admin-configured TTS providers. Auth-gated when auth is
|
|
* enabled. Never returns keys, base URLs, or ciphertext — only the data the
|
|
* client needs to render the provider picker.
|
|
*/
|
|
export async function GET(req: NextRequest) {
|
|
if (isAuthEnabled()) {
|
|
const session = await auth?.api.getSession({ headers: req.headers });
|
|
if (!session?.user) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
}
|
|
}
|
|
|
|
try {
|
|
const all = await listAdminProviders();
|
|
const visible = all.filter((p) => p.enabled).map(toPublic);
|
|
return NextResponse.json({ providers: visible });
|
|
} catch (error) {
|
|
serverLogger.warn({ err: error }, '[tts/shared-providers] list failed:');
|
|
return NextResponse.json({ providers: [] });
|
|
}
|
|
}
|