Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to XMLHttpRequest at 'http://localhost:3000/socket.io/?EIO=4&transport=polling&t=OLZ_vld' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. #16

Closed
tskxz opened this issue Dec 30, 2022 · 1 comment

Comments

@tskxz
Copy link

tskxz commented Dec 30, 2022

Im getting these errors
image

My server.js

const io = require('socket.io')(3000)

io.on('connection', socket => {
    socket.emit('chat-message', 'Hello World')
})

My script.js

const socket = io('http://localhost:3000')
socket.on('chat-message', data => {
    console.log(data)
})
@tskxz
Copy link
Author

tskxz commented Dec 30, 2022

Fixed it as #2

server.js

const io = require('socket.io')(3000, { cors: { origin: true } })

@tskxz tskxz closed this as completed Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant