import { createError, getQuery } from 'h3' import { searchAddresses } from '../../utils/geocoding' export default defineEventHandler(async (event) => { const query = getQuery(event) const rawText = typeof query.q === 'string' ? query.q.trim() : '' const rawLimit = typeof query.limit === 'string' ? Number.parseInt(query.limit, 10) : 5 const limit = Number.isFinite(rawLimit) ? Math.min(Math.max(rawLimit, 1), 8) : 5 if (rawText.length < 3) { throw createError({ statusCode: 400, statusMessage: 'Query too short' }) } const suggestions = await searchAddresses(rawText, limit) return { suggestions } })