import type { RequestHandler } from './$types';
import { registry } from '$lib/server/metrics';

export const GET: RequestHandler = async () => {
	try {
		const metrics = await registry.metrics();

		return new Response(metrics, {
			status: 200,
			headers: {
				'Content-Type': registry.contentType
			}
		});
	} catch (error) {
		console.error('Metrics collection failed:', error);

		return new Response('Metrics unavailable', {
			status: 500,
			headers: { 'Content-Type': 'text/plain' }
		});
	}
};
