0

I am making a chrome extension, and I need to check the availability of multiple websites.

I was thinking that an HTTP request could do it, or loading an img to the server and watching the onLoad event as discussed here : Javascript: Check if server is online?

What method should I use ?

Polymood
  • 397
  • 3
  • 14

1 Answers1

1

You could use an axios request to each site, check the status code of the response, and then add the website/status code pair to an object.

const serversRunning = {};

for (let server of serverList){

     const response = await axios({
             url: `{url goes here}`,
             method: "GET"
           });
     serversRunning[server] = response.status;
}

If response code is '200' it's running. I mean, it also depends on what you want to do with that information, but I feel like that would be the easiest that I know of.

or if you just want a list of running servers, change it to:

const serversRunning = [];
    
for (let server of serverList){
    
     const response = await axios({
             url: `{url goes here}`,
             method: "GET"
           });
     if (response.status == '200'){
         serversRunning.push(server);
     };
}
CVerica
  • 327
  • 1
  • 10
  • Hey Polymood, not trying to beg, but if my answer worked for you, do you want to accept it? I could use the rep (I just wanna get to 50 so I can leave comments that aren't on my own posts). – CVerica May 07 '21 at 22:12