import logger from '~~/server/utils/logger';

const ALLOWED_LEVELS = ['info', 'warn', 'error'];

export default defineEventHandler(async (event) => {
  const body = await readBody(event);
  const { level, message, meta } = body || {};

  const logLevel = ALLOWED_LEVELS.includes(level) ? level : 'info';

  logger[logLevel](message, {
    label: 'front-end',
    ...meta,
  });

  return { status: 'ok' };
});