import { ok, notFound, serverError } from 'wix-http-functions'; import { fetch } from 'wix-fetch'; export async function get_lookup(request) { const reg = request.query.reg; // Get the registration number from the request const apiKey = "d5SFtA5f2w1LoFPGiTDH44J4k1jxCVkp2ur6eMO3"; // Your DVLA API Key const options = { method: "POST", headers: { "x-api-key": apiKey, "Content-Type": "application/json" }, body: JSON.stringify({ registrationNumber: reg }) }; try { const response = await fetch("https://driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1/vehicles", options); if (response.ok) { const data = await response.json(); return ok({ body: JSON.stringify(data) }); } else { return notFound({ body: "Vehicle not found" }); } } catch (error) { console.error("API call failed", error); return serverError({ body: "Failed to fetch vehicle data" }); } }