3.0.5 • Published 4 years ago

bullet-catcher v3.0.5

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

Build Status js-standard-style

bullet-catcher

Restrict put on a gun server

This module will listen to in and run your supplied validation function against all put messages.

Usage

Install bullet-catcher from npm

$ npm i bullet-catcher

Require bullet-catcher in your gun server

const Gun = require('gun')
// MUST be required after Gun to work
require('bullet-catcher')

// This is an example validation function
function hasValidToken (msg) {
  return msg && msg && msg.headers && msg.headers.token && msg.headers.token === 'thisIsTheTokenForReals'
}

const server = require('http').createServer(Gun.serve(__dirname));

// Pass the validation function as isValid
const gun = Gun({
  file: 'data.json',
  web: server,
  isValid: hasValidToken
})

// Sync everything
gun.on('out', {get: {'#': {'*': ''}}})

server.listen(8000)

On your client add a listener for outgoing messages and enrich them with whatever you want to validate for

Gun.on('opt', function (ctx) {
  if (ctx.once) {
    return
  }
  ctx.on('out', function (msg) {
    var to = this.to
    // Adds headers for put
    msg.headers = {
      token: 'thisIsTheTokenForReals'
    }
    to.next(msg) // pass to next middleware
  })
})

Related

License

MIT

3.0.5

4 years ago

3.0.4

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.33

5 years ago

1.0.32

5 years ago

1.0.31

5 years ago

1.0.30

5 years ago

1.0.29

5 years ago

1.0.28

5 years ago

1.0.27

5 years ago

1.0.26

5 years ago

1.0.25

5 years ago

1.0.24

5 years ago

1.0.23

5 years ago

1.0.22

5 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago