import QRCode from 'qrcode' /** * Generate the /stage QR code locally. No third-party QR image service is * called at runtime, so the big screen keeps working without internet access. */ export default defineEventHandler(async (event) => { const query = getQuery(event) const text = typeof query.text === 'string' ? query.text.trim() : '' if (!text) { throw createError({ statusCode: 400, statusMessage: 'text is required' }) } if (text.length > 1024) { throw createError({ statusCode: 400, statusMessage: 'text is too long for a QR code' }) } let svg: string try { svg = await QRCode.toString(text, { type: 'svg', margin: 1, width: 320, errorCorrectionLevel: 'M', color: { dark: '#0f172a', light: '#ffffff' }, }) } catch { throw createError({ statusCode: 400, statusMessage: 'could not encode text as a QR code' }) } setResponseHeaders(event, { 'content-type': 'image/svg+xml; charset=utf-8', 'cache-control': 'public, max-age=300', }) return svg })