I have a Flask socket.io app (backend) hosted on Heroku.
I have frontend with the JS code to connect to the host at my local machine. I am getting the following error while trying to connect to the server.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://deploy-appp.herokuapp.com/socket.io/?
EIO=3&transport=polling&t=MH05dP-. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://deploy-appp.herokuapp.com/socket.io/?
EIO=3&transport=polling&t=MH05f5A. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
Link to the backend application
JS code for socket connection:
<script type="text/javascript">
var socket = io.connect('https://deploy-appp.herokuapp.com/');
socket.on('connect', function() {
console.log('connected');
});
socket.on('message', function(msg) {
document.getElementById('messages').append('<li>'+msg+'</li>');
console.log('Received message');
});
function send() {
console.log(document.getElementById('myMessage').value)
socket.send(document.getElementById('myMessage').value)
};
</script>