I want to check simple if my API endpoints are alive but I got back Firefox can’t establish a connection to the server at myURL error, I'm on 94.0.1 (64-bit) windows edition, which is based on this is supported. And I'm trying this on AWS-ec2. All of this is based on this article: https://www.w3schools.com/html/html5_serversentevents.asp
This is my HTML:
<div id="searchDatabases">
</div>
<script type="text/javascript">
if(typeof(EventSource) !== "undefined") {
// Yes! Server-sent events support!
var source = new EventSource("pingServers.php");
source.onmessage = function(event) {
document.getElementById("searchDatabases").innerHTML = event.data + "<br>";
};
} else {
// Sorry! No server-sent events support..
console.info("Not supported browser!");
}
</script>
this is in pingServers.php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
$output = shell_exec("python3 pingServers.py")
echo $output;
flush();
and this is pingServers.py
#!/usr/bin/python
import requests
import json
import html
import sys
requestpost = requests.post('MyJSONEndpoint.php')
if requestpost.status_code == 200:
print('OK')
else:
print('not OK')
So my question is how can I do this correctly?