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

Handle upgrade event to proxy WebSockets #10

Closed
wants to merge 2 commits into from

Conversation

simshanith
Copy link
Contributor

@simshanith
Copy link
Contributor Author

I can rebase & reopen against the develop branch, if preferred.

@simshanith
Copy link
Contributor Author

I tested this branch with the CLI against generator-socketio, and it appears to work well.

Steps to reproduce:

  • Clone my fork at the PR branch, cd to it.
    • git clone -b ws-upgrade https://git@github.com/simshanith/foxy.git && cd foxy
  • Install fork as local global module.
    • npm link
  • Install yo and generator-socketio globally
    • npm install --global yo generator-socketio
  • Generate the Socket.IO app in a separate folder of your choosing.
    • yo socketio
  • Correct the Gruntfile.js, removing the "false" task run attempt. (this may be a bug answering "no" to the "Do you want Bootstrap?" prompt)
  • Change the hardcoded Socket.IO client connection in public/js/app.js to be relative to origin:
var socket = io.connect(window.location.origin);
  • Build assets & launch the server via default Grunt task.
    • grunt
  • Default port for yo-socketio server is 1337. Proxy that with Foxy in another process.
    • foxy http://localhost:1337
  • Open network developer tool in browser on the Foxy URL, and make sure no more XHRs are getting triggered after upgrade, and that the WebSocket connection returned a successful 101 Switching Protocols.

After testing, you can npm unlink from the forked foxy directory to uninstall as global Foxy. Note, you will need to reinstall foxy if previously installed.

cd foxy && npm unlink && npm cache clean foxy && npm install --global foxy

Expose `upgrade` proxy handler on foxy `app` instance as `handleUpgrade`
Attach `upgrade` listener in CLI server creation.

Issue shakyShane#2
@simshanith
Copy link
Contributor Author

Rebased & force pushed to fix a single-quote instead of double-quote JSLint rule. Appveyor didn't seem to like that.

Anyway my second commit gives a "true positive" from what I can tell, after taking the "false positive" from my first commit to a "true negative" and then back around to "true positive".

Note, however, that dependents such as BrowserSync will need to attach the handler themselves after creating the http(s) server. It should be exposed as app.handleUpgrade.

@shakyShane shakyShane closed this in 7d1e291 May 3, 2015
@simshanith simshanith deleted the ws-upgrade branch May 5, 2015 22:07
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

Successfully merging this pull request may close these issues.

None yet

2 participants