Last active
June 23, 2021 21:19
-
-
Save justinecodez/8c04ceffa4a475472d306134e8bdb787 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const fetch = require('node-fetch') | |
const app = express(); | |
app.use(express.json()); | |
app.use(express.urlencoded({ extended: false })); | |
const urls = [ | |
"http://www.google.com", | |
"http://www.facebook.com", | |
"http://www.twitter.com" | |
] | |
app.get('/ping', (req, res, nex) => { | |
setInterval(() => { | |
let tryUrl1 = 0; | |
let tryUrl2 = 0; | |
let tryUrl3 = 0; | |
urls.forEach((url,index) => { | |
fetch(url). | |
then((response)=>{ | |
if(!response.status === 200 && index === 0){ | |
tryUrl1++; | |
} | |
if(!response.status === 200 && index === 1){ | |
tryUrl2++; | |
} | |
if(!response.status === 200 && index === 2){ | |
tryUrl3++; | |
} | |
if(tryUrl1 === 3 || tryUrl2 === 3 || tryUrl3 === 3 ){ | |
let date = new Date().now(); | |
res.send({url, date}) | |
} | |
res.send({url}) | |
}) | |
}); | |
}, 3000); | |
}) | |
module.exports = app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment