Created
August 18, 2021 09:05
-
-
Save itgoldman/ef6f90dc1c9cdab8722b1ccbfb4c60bb to your computer and use it in GitHub Desktop.
This file contains 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
// server serving index.html | |
var express = require("express"); | |
var path = require("path"); | |
var app = express(); | |
app.get("/", function(req, res) { | |
res.sendFile(path.join(__dirname, "./index.html")); | |
}); | |
app.listen(3000); | |
console.log("Express started on port 3000"); | |
if (true) { | |
// calling API every 5 seconds or so. | |
// this is immitating long process. | |
const https = require("https"); | |
const axios = require("axios"); | |
const agent = new https.Agent({ rejectUnauthorized: false }); | |
var x = 1; | |
var notify = function() { | |
// notify client | |
axios | |
.post( | |
"https://rejax.io:3001/api/server", | |
{ | |
app_key: "KEYzoVONRA4CdMvDzBZXytPyebwMf3sLrLh", | |
app_secret: "SECRETLJAQpPaB6p31q5UOzOBtsmmnbLqFY6z4", | |
channel: "my-channel-name", | |
text: "hello from server at " + new Date() | |
}, | |
{ httpsAgent: agent } | |
) | |
.then(res => { | |
console.log(res.data); | |
}) | |
.catch(error => { | |
console.error(error.code); | |
}); | |
// do some work | |
x++; | |
setTimeout(notify, x * 1000); | |
}; | |
notify(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
and this is the client: