Advertisement
RemcoE33

Url redirects

May 4th, 2022
57
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 data = await request.json();
  12.     output.push(data);
  13.   }
  14.  
  15.   //Returning data to apps script function.
  16.   return new Response(JSON.stringify(output), {
  17.     headers: {
  18.       "content-type": "application/json",
  19.     },
  20.   });
  21. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement