Skip to content

Instantly share code, notes, and snippets.

@pfrazee
Last active August 29, 2015 13:56
Show Gist options
  • Save pfrazee/9037612 to your computer and use it in GitHub Desktop.
Save pfrazee/9037612 to your computer and use it in GitHub Desktop.
Server Objects, and How VMs are Bridged

Server Objects, and How VMs are Bridged

diagram

Every VM has multiple server objects

  • they make up the httpl:// namespace
  • may be functions or objects with a handleLocalRequest method

"Bridge" servers wrap the postMessage interfaces

  • a request to httpl://the-worker is postMessageed
  • the worker generates a response
  • the response is postMessageed back

Bridges have two handlers: local and remote

  • handleLocalRequest does the serialize and postMessage. It takes requests from the local VM
  • handleRemoteRequest generates responses to postMessage back. It takes requests from the other VM
  • for bridges, applications only define a handleRemoteRequest because handleLocalRequest is standard: it always serializes the request and sends it to be fulfilled by the other VM's handleRemoteRequest

Workers define all behaviors in their handleRemoteRequest, but they can proxy to other httpl hosts within their VM.

  • in the worker:
  • local.addServer('config', require("config-server.js"));
  • myBridgeServer.proxy('/config', 'httpl://config');
  • now httpl://the-worker/config is handled by config-server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment