Solution 1 :


// Allow all origins'*');


Problem :

I’m having trouble migrating my locally hosted chat application using to my live cloud server. I am aware there are solutions out there, however, I cannot find anything that solves my problem.

I am receiving “Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at…. (Reason: CORS request did not succeed)”

const io = require('')(3000)

io.on('connection', socket => {
    socket.on('new-user', name => {
        users[] = name
        socket.broadcast.emit('user-connected', name)
    socket.on('send-chat-message', message => {
        socket.broadcast.emit('chat-message', {message: message, name: 
    socket.on('disconnect', () => {
        socket.broadcast.emit('user-disconnected', users[])
       delete users[]



Above is the server.js file.

    const socket = io('<url>:3000')
    const messageForm = document.getElementById('send-container')
    const messageInput = document.getElementById('message-input')
    const messageContainer = document.getElementById('message-container')

This is the script my app is using, the is replaced by mine, it just masked on here.

Things I have tried:

  • Setting headers using “Header set Access-Control-Allow-Origin” in my Apache & Nginx config
  • Changing the url on the script
  • Changing the ports

So far I’ve no luck, please help me!!


Leave a Reply

Your email address will not be published. Required fields are marked *