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

Google Chrome 16: XMLHttpRequest cannot load http://localhost:8000/socket.io/1/?t=1330690238048. Origin null is not allowed by Access-Control-Allow-Origin. #776

Closed
Fannon opened this issue Mar 2, 2012 · 7 comments

Comments

@Fannon
Copy link

Fannon commented Mar 2, 2012

Hi there,

If i want to establish a socket.io connection from Google Chrome I get this error message (console):

XMLHttpRequest cannot load http://localhost:8000/socket.io/1/?t=1330690238048. Origin null is not allowed by Access-Control-Allow-Origin.

Firefox works fine.

Am I doing something wrong?

Greets, Simon

@yipingshui
Copy link

use io.connect("http://ip:port")

@tonistiigi
Copy link

I'm also hitting this and changing localhost to IP doesn't seem to make a difference.

Seems to only happen in Chrome/Windows when file that connects to socket.io is opened from the hard drive instead of a webserver. Fine in Mac/Linux.

Regression at e4a9342 #630

@DarkMukke
Copy link

i have the same problem

[edit] i solved the 404 problem, the proxy only allowed .js calls

this is my server

var io = require('socket.io').listen(12080);
io.set('origins','*');
io.set('transports', [
    'websocket'
    , 'flashsocket'
    , 'htmlfile'
    , 'xhr-polling'
    , 'jsonp-polling'
]);

this is my lighttpd setup serving socket.io on a subdomain as a proxy as alot of work envroiments only allow cinnection over 443 and 80

$HTTP["host"] == "iw131.itswar.be" {
    setenv.add-response-header = ( "Access-Control-Allow-Origin" => "http://api131.itswar.be",
                                        "Access-Control-Allow-Credentials" => "true" )
        server.document-root = "/var/www/iw131.itswar.be/public"
    accesslog.filename = "/var/log/lighttpd/dev/access-iw131.log"
    server.error-handler-404 = "/404"
        url.rewrite-if-not-file  = (
            ".*\?(.*)" => "index.php?$1",
            "." => "index.php"
        )
}

proxy.balance = "fair"

$HTTP["host"] == "api131.itswar.be" {
        setenv.add-response-header = ( "Access-Control-Allow-Origin" => "http://iw131.itswar.be" ,
                                        "Access-Control-Allow-Credentials" => "true")
        $HTTP["url"] =~ "\.(js)$" {
                proxy.server  = ("" => (
                        ("host" => "127.0.0.1", "port" => 12080)
                ))
        }
}

@yipingshui
Copy link

Have you add the "io.sockets.on('connection', function (socket) {...})" to your server?

At 2012-04-02 22:30:08,Mukke reply@reply.github.com wrote:

i have the same problem

this is my server

var io = require('socket.io').listen(12080);
io.set('origins','*');
io.set('transports', [
  'websocket'
  , 'flashsocket'
  , 'htmlfile'
  , 'xhr-polling'
  , 'jsonp-polling'
]);

this is my lighttpd setup serving socket.io on a subdomain as a proxy as alot of work envroiments only allow cinnection over 443 and 80

$HTTP["host"] == "iw131.itswar.be" {
   setenv.add-response-header = ( "Access-Control-Allow-Origin" => "http://api131.itswar.be",
                                       "Access-Control-Allow-Credentials" => "true" )
       server.document-root = "/var/www/iw131.itswar.be/public"
   accesslog.filename = "/var/log/lighttpd/dev/access-iw131.log"
   server.error-handler-404 = "/404"
       url.rewrite-if-not-file  = (
           ".*\?(.*)" => "index.php?$1",
           "." => "index.php"
       )
}

proxy.balance = "fair"

$HTTP["host"] == "api131.itswar.be" {
       setenv.add-response-header = ( "Access-Control-Allow-Origin" => "http://iw131.itswar.be" ,
                                       "Access-Control-Allow-Credentials" => "true")
       $HTTP["url"] =~ "\.(js)$" {
               proxy.server  = ("" => (
                       ("host" => "127.0.0.1", "port" => 12080)
               ))
       }
}

Reply to this email directly or view it on GitHub:
#776 (comment)

@DarkMukke
Copy link

i edited my post

turned out my vhost for the proxy was only allowing .js files
but apperatnly websockets wont work over X-Domain, so im back to using same domain on different port

i think crossdomain should not count if its a subdomain , like if the page is served from www.domain.com and socket.io is served from api.domain.com

firefox hasnt problems with this, opera doesnt allow websockets by default and chrome is too strict, i think websockets will be for the next genereation of browsers

@kreinloo
Copy link

kreinloo commented Apr 5, 2012

I've added a simple HTTP file server to my app, so instead of opening "file:///home/me/file.html" I open "http://localhost:port" in my browser (chromium).

I used this module: https://github.com/cloudhead/node-static

@DarkMukke
Copy link

yes i understand, the problem i'm having though is that alot of clients work in controlled environments (proxies/port blockers) so only have access to common ports (80,443,25,etc), unfortunately those ports are already in use on my server
so i made a proxy to serve the socket.io from the node server port (12080) to port 80

This issue was closed.
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

5 participants