Skip to content

Instantly share code, notes, and snippets.

@Raynos Raynos/client.js
Created Aug 6, 2012

Embed
What would you like to do?
Seaport proxy API
var seaport = require("seaport-proxy")
, boot = require("boot")
, mdm = boot("/boot")
, ports = seaport(mdm)
var stream = ports.get("magic@1.2.x")
stream.on("data", function (data) {
// beep boop!
console.log(data)
})
var seaport = require("seaport")
, net = require("net")
, ports = seaport.connect("localhost", 9090)
var server = net.createServer(function (stream) {
stream.end("beep boop!")
})
ports.service("magic@1.2.3", function (port, ready) {
server.listen(port, ready)
})
var seaport = require("seaport-proxy")
, ports = seaport.connect("localhost", 9090)
var Router = require("routes").Router
, streamRouter = new Router()
// ROUTE THE STREAMS INTO THE PROXY
streamRouter.addRoute("/seaport/get/:service", ports.get)
streamRouter.addRoute("/seaport/query/:service", ports.query)
var boot = require("boot")
var sock = boot(function (stream) {
var route = streamRouter.match(stream.meta)
if (route) {
// PASS THE STREAM INTO THE PROXY
route.fn(stream, route.params)
}
})
sock.install(someHttpServer, "/boot")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.