Flotype / now

NowJS makes it easy to build real-time web apps using JavaScript
http://www.nowjs.com
MIT License
1.91k stars 175 forks source link

replased host and port options with ioUri and scriptSource #122

Closed ryankoppenhaver closed 13 years ago

ryankoppenhaver commented 13 years ago

The motivation for this patch is to auto-host now.js on an https only server, but hopefully it makes things a little more flexible too.

Currently, nowjs.initialize() takes 'host' and 'port' options, which stuffs into the client-side script, and uses them to (1) construct an absolute URI to load the socket.io client script, and (2) to initialize the io.Socket object. This has a couple of limitations: the URI for the script is hard-coded as http (not -s), there's no way to pass the "secure" flag to socket.io, and there's no way to specify a different host for the socket.io script. (For that last one, I admit I'm not sure why someone might auto-host now.js, but not socket.io, but hey.)

With 0.7, socket.io is initialized with a URI, and now.js currently just concatenates the server and port to create this URI. With this patch, the user specifies the URI ("ioUri" in the options object), allowing it to be https. This replaces the 'host' and 'port' options. The default case, auto-hosted now.js and socket.io, with no URI specified, "just works" for http (still) and https (new!).

I've also created another option ("scriptSource"), so that one can specify a base URI for socket.io, and any other client-side dependencies, separately.

steveWang commented 13 years ago

I wonder what would happen if uriin the code as it stands right now were changed to begin with // as opposed to http://. Would that obviate this pull request? (the first part, at least)

ryankoppenhaver commented 13 years ago

Yeah, that works just fine for the socket.io over https part. (And, as I said, I don't know if there's any actual demand for the rest of it.)

steveWang commented 13 years ago

I think all the desired functionality has been implemented in some form or another. (options.protocol for extra specificity, namely serving the HTML via file:/// and having NowJS served via node, which was broken by the use of //.)