-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
CORS problem (No 'Access-Control-Allow-Origin') on client #2294
Comments
You can use the var allowedOrigins = "domain_1:* domain_2:*";
io(server,{origins:allowedOrigins}); on the server you want to connect to. |
Still does not work. Here is my code: // page: http://localhost:63342/rabbit/rabbit_client.html
var allowedOrigins = "http://localhost:63342";
var client = io('http://127.0.0.1:15674/stomp', {
origins: allowedOrigins // I think it should be written like this right? Otherwise there would be syntax error
});
|
This is in the browser console right? |
Yeah, right! |
I am a bit confused by your code. The allowed origins option goes in your socket.io server not in the client i.e. in node.js code not in browser javascript that is part of a html page. Also I usually use a wildcard on the port and you can specify multiple allowed origins, just space them out like so:
On the client side
|
So the problem is in that I do not have In the default example of this RabbitMQ, there is used SockJS and this library sets proper And that is my question, just how to set |
As far as I know, access control headers aren't set from the client. They are set on the servers when they serve requests from the clients. You need to add the server that serves rabbit_client.html to the allowed origins of your scala server. Also socket.io uses it's own protocol and most likely won't work with a scala back end. It has numerous client apis (iOS, Boost C++, android, etc) but it needs a socket.io server and so far as I am aware there is only a socket.io server for node.js. You could use pure web sockets on both sides, I'm not certain but I think there is a web socket implementation for scala. |
Thanks a lot for your answer, it sounds reasonable. Yeah I see, there is not possibility to do that according to this article on Mozilla hacks, but there is such possibility as I mean SockJS works out of the box with the same server, but socket.io does not, and the problem seems to be this CORS for sure. Take a look at their part of code, it looks pretty simple and I think only because of that, it works. |
The sockjs code you posted is using xhr polling. |
The sockjs uses xhr polling only for connection purposes, so just in order to make handshake. Take a look at this screen: As you can see there is only one xhr and then it is websocket connection. So I just want to achieve the same connection but only through the SocketIO. |
hey mates, Im with the same problem, Im new in websockets and I have a server that is working trying to connects with free websocket clients on internet, but when I use the same URL with socket.IO I get the same error than you. Any new @AlexanderTserkovniy ? Thanks |
Same problem here. I'd like to allow all origins access to my socket, but also allow credentials, because I'll authenticate clients using JSON web tokens. I can't specify allowed origins on the server because I won't know them in advance. Having the option to set |
Here's the line of code: https://github.com/socketio/socket.io-client/blob/78f61c3abcc953532ec5c30e1b8cd485b9ea3656/socket.io.js#L1430 Does Socket.IO rely on cookies or the authorization header? If not, couldn't this setting be made optional? |
Are some of you guys running your server @ heroku? |
Guys, I have tried a lot with express with no success. However, it works just fine with http. `var server = require("http").createServer(onRequest); function onRequest(req,res){ io.on('connection', function(socket) {
}); server.listen(3002, function(){ |
It appears that Socket.io's definition of "origin" is somewhat different from the normal one (at least the one on MDN): Socket.io doesn't seem to want the scheme to be included. See this block of code which checks the origin against the It seems an open question to the project authors whether this constitutes a bug. |
I'm using cors extension for google chrome and socket.io for chat application on my nodejs+Angular2 app but it is giving follwing error. |
@hasanraza-axovel Hi dude, I have similar problem, did you end up solve this? |
I've added this
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", 'http://localhost:4200'); //<--
you can change this with a specific url like http://localhost:4200
res.header("Access-Control-Allow-Credentials", true);
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header("Access-Control-Allow-Headers",
'Origin,X-Requested-With,Content-Type,Accept,content-type,application/json,Authorization');
next();
});
in app.js. Make sure that this will be added before the api routes.
…On Sat, Nov 25, 2017 at 11:17 AM, Herbert Wang ***@***.***> wrote:
@hasanraza-axovel <https://github.com/hasanraza-axovel> Hi dude, I have
similar problem, did you end up solve this?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2294 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/Ace0Lu9EPmoeAIql3QfeenpEHf-D5O0Nks5s56nWgaJpZM4GaEen>
.
|
Hi guys, sorry, do not work with it anymore. Cannot help :( |
Can you send me you code?
…On Fri, Dec 1, 2017 at 2:31 PM, AlexanderTserkovniy < ***@***.***> wrote:
Hi guys, sorry, do not work with it anymore. Cannot help :(
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2294 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/Ace0LlzOEGY3-d_Ks1Z0QtKZhDIN7F2Tks5s78BegaJpZM4GaEen>
.
|
For folks using feathers with socket.io
|
@turnerhayes you are absolutely right, the protocol was not taken in account in the origin check (added in #3198) |
I'm closing this, as I think the first issue should be resolved by now. If not, do not hesitate to open another issue with all details, thanks!
io.origins(['https://foo.example.com:443']); |
add this to your httpd.conf file Header set Access-Control-Allow-Origin 'origin-list' https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSMissingAllowOrigin it worked for me |
Hi all,
Typically if you do have server with sockets on another domain and you do simple first line
io('YOUR_HOST')
, you will receive this message:XMLHttpRequest cannot load YOUR_HOSTsocket.io/?EIO=3&transport=polling&t=1446467052356-0. No 'Access-Control-Allow-Origin'...
First appeared in head, that I need to look at documentation and find out how to set it from there, but eventually I did not find anything because of pure documentation.
Then I entered source code and the only 2 usages of
setRequestHeader
method, which is actually allow you to do that, is only for setting content-type if POST method is chosen.Could you help me to fix this issue?
The text was updated successfully, but these errors were encountered: