# bouncer

> A service router that uses MDNS and bouncy to do magic!

Latest version **0.0.5** (published 2012-06-14) · 0 weekly downloads

## Install

```sh
npm install bouncer
pnpm add bouncer
yarn add bouncer
bun add bouncer
```

Provides the command `bouncer`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2012-06-14 |
| First published | 2012-05-30 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | 0.6.x |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Addison Higham |
| Maintainers | addisonj |

## Links

- npm: https://www.npmjs.com/package/bouncer
- Repository: https://github.com/addisonj/bouncer
- npm.io page: https://npm.io/package/bouncer

## Dependencies (3)

- [mdns](https://npm.io/package/mdns.md) 0.0.6
- [bouncy](https://npm.io/package/bouncy.md) 1.3.1
- [commander](https://npm.io/package/commander.md) 0.6.0

## Recent versions

- 0.0.5 (latest) — 2012-06-14
- 0.0.4 — 2012-06-04
- 0.0.3 — 2012-06-04
- 0.0.2 — 2012-05-30
- 0.0.1 — 2012-05-30

## README

#Bouncer
Bouncer is a simple router that uses MDNS and substack's bouncy to magically discover your apps and services to hit and fallback when neccessary. 

##Install
###Prereqs
For bouncy to be useful, you need to redirect a wildcard subdomain to localhost (*.dev.local for example). There are lots of methods to do this, but here is one way for OSX.

(shamelessly borrowed from http://onemoredigit.com/post/2155404559/wildcard-etc-hosts-an-alternative)

1. install dnsmasq
``` 
brew install dnsmasq
```
2. copy the example config
``` 
cp /usr/local/Cellar/dnsmasq/2.55/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
```
3. edit dnsmasq.conf to include the following

```
address=/com.local/127.0.0.1
listen-address=127.0.0.1
```
where "com.local" is the domain you want to redirect on, I use dev.local
4. (optional) Add the dnsmasq launchd config (provided by homebrew) to your system. Homebrew tells you how to do this.

###Installation
1. install it
```
npm install -g bouncer
```
2. Advertise your services (see below)
3. run bouncer
```
bouncer -c /path/to/conf.json
```

NOTE: defaults to ~/.bouncer.json if no config is passed

See below for config info

##Advertising services
Bouncer relies on MDNS (aka. Bounjour, ZeroConf) to discover your services, in order for this to work however, you must create and advertisement for that service

app.js
```
var advertise = require('bouncer').advertise
...
var options = {secret: "cheesecake"}
app.listen(PORT, advertise("service_name", PORT, options))
```

See below for list of options

##Config
Bouncer uses a json config file to define a secret, a list of services with fallbacks, and other options

sample_config.json (obvs without the comments!)
```
  // port to listen on
  "port" : 8000,
  // secret to use (match with your advertisement)
  "secret" : "mysecret",
  // OPTIONAL - key used to encrypt
  "key": "123456789123",
  // OPTIONAL - a fallback if no corresponding service is found
  "globalFallback" : "http://mydomain.com",
  // only bind with local instances of the service, default to false
  "localOnly": false,
  // a hash of service names and the fallback url to use
  "services" : {
    "service1" : "service1.mydomain.com",
    "service2" : "service2.mydomain.com",
  }
```

###Advertise
the advertise options hash taskes a secret and a key, match to above

##API
If you want to use Bouncer programatically, you can.

```
var Bouncer = require('bouncer').Bouncer
var bouncer = new Bouncer(opts)
bouncer.start()
```

opts takes all the same options as the json config and also a few functions

onServiceUp(mdnsRecord) - fired when a service is registered

onServiceDown(mdnsRecord) - fired when a service is removed

onGlobalFault(request, bouncyInstance, serviceName) - handle global faults

onServiceFault(request, bouncyInstance, serverObj) - handle faults for an individual services, serverObj is {name: "service_name", hosts; [mdnsRecord]}

verifyHost(mdnsRecrd) - return true if you want to accept the service

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