要确定网站是否在线,我计划制作一个简单的ping脚本,并通过REST端点返回一个布尔值,或者让电话定期检查更新的值;但我觉得必须有更好的方法。通知设备更改的最佳方法是什么?如果布尔值返回true,是否有一种方法可以使终结点将推送通知发送到本地应用程序;或200状态?
const express = require('express')
const domainPing = require('domain-ping')
const port = 4000
const app = express()
cron.schedule("* * * * *", function() {
domainPing("example.com")
.then(resp => resp)
/*
* resp: {domain: "example.com", ip: "93.184.216.34", online: true, ping: false, statusCode: 200, success: true}
* */
return [resp.online, resp.status] //How can I send a push notification here to react-native?
.catch(err => {
console.log(err)
});
});
app.listen(port, () => console.log(`http://localhost:${port}!`))