RemcoE33

TESCO_Deno

Apr 7th, 2022 (edited)
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Importing dependencies
  2. import { listenAndServe } from "https://deno.land/std/http/mod.ts";
  3.  
  4. //Create server that listens to incomming requests
  5. listenAndServe({ port: 8000 }, async (req) => {
  6.   const { urls } = await req.json();
  7.   const output = [];
  8.  
  9.   for (let i = 0; i < urls.length; i++) {
  10.     const request = await fetch(urls[i]);
  11.     const html = await request.text();
  12.     const data = JSON.parse(
  13.       /<script type="application\/ld\+json">(.*?)<\/script>/gims.exec(html)[1]
  14.     )[2];
  15.  
  16.     output.push(data);
  17.   }
  18.  
  19.   //Returning data to apps script function.
  20.   return new Response(JSON.stringify(output), {
  21.     headers: {
  22.       "content-type": "application/json",
  23.     },
  24.   });
  25. });
  26.  
Add Comment
Please, Sign In to add comment