npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stomp-proxy

v0.0.2

Published

A stomp proxy with frame re-writing and error handling

Downloads

30

Readme

stomp-proxy

A stomp proxy with frame re-writing and error handling

Stomp is a simple protocol for sending messages that works over both TCP or a websocket.

This project exposes a single simple class that allows for proxying and re-writing stomp frames, this is useful for exposing a stomp endpoint publicly with custom authentication or custom functionality

Usage

var StompProxy = require("stomp-proxy")
// connect to STOMP server, such as rabbitmq speaking stomp
var upstreamConn = net.connect({port: 61613})

// attach a handler for each stomp command
function makeProxy(client, upstream) {
  var proxy = new StompProxy(client, upstream)
  // rewrite frames by passing them to the callback
  proxy.onSubscribe = function(session, frame, cb) {
    frame.headers.destination = "/topic/foo.bar.baz"
    cb(null, frame)
  }
  // send error frames by passing an error to the callback
  proxy.onSend = function(session, frame, cb) {
    cb(new Error("no sends allowed"))
  }
  // support custom auth and sessions (in-memory only)
  proxy.onConnect = function(session, frame, cb) {
    session.username = frame.headers.login
    if (frame.headers.passcode != "crispy_treats") {
      return cb(new Error("invalid passcode"))
    }
    frame.headers.login = "guest"
    frame.headers.passcode = "guest"
    cb(null, frame)
  }

  // rewrite frames from the server
  proxy.onMessage = function(session, frame, cb) {
    frame.headers["proxy-via"] = "stomp-proxy"
    frame.headers.user = session.username
    cb(null, frame)
  }

  // you need to call start after attaching handlers
  proxy.start()
  return proxy
}
// can be TCP
var server = net.createServer(function(conn) {
  var proxy = makeProxy(conn, upstreamConn)
})
// or a websocket
shoe(function(conn) {
  var proxy = makeProxy(conn, upstreamConn)
})

Other random features

  • Support arbitrary stomp commands to add your own functions
// just attach a handler, client would send DELETE
proxy.onDelete = function(session, frame, cb) {
  myApi.delete(frame.headers.destination, function(err) {
    if (err) return cb(err)

    // don't send the frame back to the upstream as it wouldn't understand the method
    cb()
  })
}
  • Passthrough mode when you don't want to rewrite in one direction
// we don't wan to rewrite server frames, can be slightly more efficent
var proxy = new StompProxy(client, upstream, {serverPassthrough: true})

More examples

  • (backside-proxy)[https://github.com/backside/backside-proxy/blob/master/lib/proxy.js]

License

MIT

TODO

  1. Add a way to sync/persist sessions between multiple hosts

Contributing

Open a PR, add a test