Connect to NowJS through a subdomain

259 views
Skip to first unread message

james33

unread,
Dec 29, 2011, 4:11:12 PM12/29/11
to nowjs
I'm trying to use CloudFlare with my Node/NowJS app, but since
CloudFlare acts as a proxy, web-sockets won't work directly. The only
way to make them work is to do them on a subdomain that isn't routed
through CloudFlare, so I setup a socket.domain.com subdomain to do the
web-socket connection with. I then changed the last line of now.js to
use the subdomain, but it doesn't seem to work. The socket.io
connection seems to be established fine, but nothing in the now
namespace seems to work now. Is this just not possible, or am I doing
it wrong?

Eric Zhang

unread,
Dec 31, 2011, 5:52:58 AM12/31/11
to no...@googlegroups.com
Hi James,

NowJS works fine with crossdomain and crossport configurations, however the issue is likely that the CloudFlare proxy is unable to forward websocket connections (I am not actually sure, haven't tried but that is a common issue with many reverse proxies).

You want to explicitly disable websockets and give it a try:

`nowjs.initialize(httpServer, {socketio: {transports: ['xhr-polling', 'jsonp-polling']}});`



Eric
--
Co-Founder @ Flotype, makers of NowJS

james33

unread,
Jan 2, 2012, 3:30:07 PM1/2/12
to nowjs
It doesn't, but it will work with websockets if you use a subdomain
that isn't using the CloudFlare proxy. When I setup NowJS to use the
subdomain, it is able to make the connection, but none of the client-
side functions on now get called (so the socket connection is made
through socket.domain.com, and the client is seeing just domain.com).

On Dec 31 2011, 4:52 am, Eric Zhang <e...@nowjs.com> wrote:
> Hi James,
>
> NowJS works fine with crossdomain and crossport configurations, however the
> issue is likely that the CloudFlare proxy is unable to forward websocket
> connections (I am not actually sure, haven't tried but that is a common
> issue with many reverse proxies).
>
> You want to explicitly disable websockets and give it a try:
>
> `nowjs.initialize(httpServer, {socketio: {transports: ['xhr-polling',
> 'jsonp-polling']}});`
>
> Eric
>

james33

unread,
Jan 2, 2012, 3:52:42 PM1/2/12
to nowjs
It doesn't, but it will work with websockets if you use a subdomain
that isn't using the CloudFlare proxy. When I setup NowJS to use the
subdomain, it is able to make the connection, but none of the client-
side functions on now get called (so the socket connection is made
through socket.domain.com, and the client is seeing just domain.com).

On Dec 31 2011, 4:52 am, Eric Zhang <e...@nowjs.com> wrote:
> Hi James,
>
> NowJS works fine with crossdomain and crossport configurations, however the
> issue is likely that the CloudFlare proxy is unable to forward websocket
> connections (I am not actually sure, haven't tried but that is a common
> issue with many reverse proxies).
>
> You want to explicitly disable websockets and give it a try:
>
> `nowjs.initialize(httpServer, {socketio: {transports: ['xhr-polling',
> 'jsonp-polling']}});`
>
> Eric
>

Eric Zhang

unread,
Jan 2, 2012, 4:36:29 PM1/2/12
to no...@googlegroups.com
Ok I see.

Are there any errors or warnings printed on either the server or the client?

james33

unread,
Jan 2, 2012, 6:31:21 PM1/2/12
to nowjs
No, there's no errors or warnings on either end. This is the
connection info pulled from Chrome: http://i.imgur.com/pKQaj.jpg and
http://i.imgur.com/yAXBS.jpg.

Maybe I'm setting it up wrong? I'm including http://socket.domain.com/nowjs/now.js
on http://domain.com/app. This works without issue if I include
http://domain.com/nowjs/now.js instead, and the only difference I see
between the 2 files is on the last line with the subdomain.

Eric Zhang

unread,
Jan 2, 2012, 7:03:06 PM1/2/12
to no...@googlegroups.com
It looks like the connection is being fully established fine. Does it work if you disable websockets (ie. does it work with just jsonp-polling enabled as a transport?)

Eric

james33

unread,
Jan 2, 2012, 7:20:13 PM1/2/12
to nowjs
Nope, still doesn't work. Connects fine with xhr-polling, but my app
won't work unless I go to socket.domain.com instead of just
domain.com.

On Jan 2, 6:03 pm, Eric Zhang <e...@nowjs.com> wrote:
> It looks like the connection is being fully established fine. Does it work
> if you disable websockets (ie. does it work with just jsonp-polling enabled
> as a transport?)
>
> Eric
>
>
>
>
>
>
>
>
>
> On Mon, Jan 2, 2012 at 3:31 PM, james33 <jame...@gmail.com> wrote:
> > No, there's no errors or warnings on either end. This is the
> > connection info pulled from Chrome:http://i.imgur.com/pKQaj.jpgand
> >http://i.imgur.com/yAXBS.jpg.
>
> > Maybe I'm setting it up wrong? I'm including
> >http://socket.domain.com/nowjs/now.js
> > onhttp://domain.com/app. This works without issue if I include
> >http://domain.com/nowjs/now.jsinstead, and the only difference I see

Eric Zhang

unread,
Jan 2, 2012, 7:22:45 PM1/2/12
to no...@googlegroups.com
Is now.ready(..) being triggered on the client?

james33

unread,
Jan 2, 2012, 7:48:20 PM1/2/12
to nowjs
Okay so now that I've been doing some more tests, it appears that on
the server-side, I'm unable to access the session cookie from the
subdomain. However, I'm writing the cookie to .domain.com, so it
should be able to from any subdomain. Any ideas?

james33

unread,
Jan 2, 2012, 7:49:58 PM1/2/12
to nowjs
this.user.cookie['connect.sid'] returns 'undefined' in
everyone.on('connect', ...)

james33

unread,
Jan 4, 2012, 1:27:35 PM1/4/12
to nowjs
So it looks like this goes all the way to socket.io. I looked at the
headers it returns in the handshake, and it doesn't return the cookie
unless the client and the connection use the same sub-domain, even
though the cookie is set to .domain.com. Is that the correct behavior?

Eric Zhang

unread,
Jan 10, 2012, 11:22:29 AM1/10/12
to no...@googlegroups.com
Interesting. I haven't played around with setting cookies on subdomains but I imagine that if its not working it would be the way the cookie is being set rather than socket.io's implementation.

Regardless, a cookie shouldn't be necessary for things to work anyways?
Reply all
Reply to author
Forward
0 new messages