# stomp-proxy

> A stomp proxy with frame re-writing and error handling

Latest version **0.0.2** (published 2014-06-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install stomp-proxy
pnpm add stomp-proxy
yarn add stomp-proxy
bun add stomp-proxy
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2014-06-10 |
| First published | 2014-05-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | addisonj |
| Maintainers | addisonj |
| Keywords | stomp, proxy |

## Links

- npm: https://www.npmjs.com/package/stomp-proxy
- Repository: https://github.com/backside/stomp-proxy
- Issues: https://github.com/backside/stomp-proxy/issues
- npm.io page: https://npm.io/package/stomp-proxy

## Dependencies (2)

- [async](https://npm.io/package/async.md) ~0.9.0
- [stompjs](https://npm.io/package/stompjs.md) ~2.3.1

## Recent versions

- 0.0.2 (latest) — 2014-06-10
- 0.0.1 — 2014-06-10
- 0.0.0 — 2014-05-24

## 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
```JavaScript
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
```JavaScript
// 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
```JavaScript
// 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

---
_Source: https://npm.io/package/stomp-proxy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
