import { Handlers } from "$fresh/server.ts"; export const handler: Handlers = { async POST(_req, ctx) { const requestPackages: Object = await _req.json(); // Loop through items console.log(typeof requestPackages) let packageUrls: any[] = []; for (let packageName in requestPackages) { packageUrls = [ ...packageUrls, `https://registry.npmjs.org/${packageName}` ]; } const packageDetailsResponse = await fetchPackageDetails(packageUrls); const packageDetails = Object.keys(requestPackages).map((packageName, index) => { return { [packageName]: packageDetailsResponse[index] } }) return Response.json({ packageDetails }); }, }; async function fetchPackageDetails(packageUrls: any[]) { return await Promise.all( packageUrls.map(url => fetch(url).then(res => res.json())) ) }