javascript - "Cross origin requests are only supported for HTTP." with Node.js -
the following code in client app:
const socket = io('${location.protocol}//${location.hostname}:8090');
is giving me following error in browser:
xmlhttprequest cannot load http://${location.protocol}/socket.io/?eio=3&transport=polling&t=lrlutss. cross origin requests supported http.
my client code run using node.js via npm start
"http://localhost:3000" automatically refreshed in browser update code.
it appears ${location.protocol}
not being substituted in string , it's still in url when socket.io tries use url. because browser not support specific es6 feature.
you can work around constructing url string old fashioned way string addition.
const socket = io(location.protocol + '//' + location.hostname + ':8090');
and, should using backticks string delimiters if expect substitution work reliably supported.
Comments
Post a Comment