1.4.3 • Published 5 years ago

@bblabs/listen-server v1.4.3

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

listen-server

Build Status

A simple server that captures and allows you to inspect those via JSON.

This is intended to be a layer added into a local app stack where you might not really need another application running. Could also be useful in testing scenarios.

Install

npm install --save @bblabs/listen-server

Usage

# run on 3000
node run src/index.js

# run on 8080
PORT=8080 node run src/index.js

Then a client can make a request to that URL and it will be captured. To see what requests have been made, you can visit http://localhost:3000/_/post (for POST request for example). Current the requests are just stored in a in-memory Sqlite database (you can change it to a file below, if you want it to persist beyond usage).

Environment variables:

VariableDefault
PORT3000
SQLITE_DB:memory:

Docker

Build your own: docker build -t listen-server .

Or run it via docker-compose: docker-compose up

You should also be able to specify environment variables as well.

Customize output

You can add an event handler to change up the return if you want:

const server = require('@bblabs/listen-server');

// change up the response and returned data to your own
// data if you want. there are events for 'request' and
// 'request.(get|post|put|delete|options)'
server.on('request', (req, res, doc) => {
  res.append('X-Something', 'Value');
  return {custom: 'doc'};
});

server.start();

Event handlers need to return a value, which will then be returned as JSON. If false is returned, then the event handlers will stop after this call, so you can use this to send your own custom, non-JSON values via the res object.

View captured data

You can view data that has been captured by navigating to the /_/METHOD endpoint. You can also apply fileters. For example, you can view post requests to /contact/ with:

curl http://localhost:3000/_/post?path=/contact

Available filters:

  • path: filter for paths that exactly match
  • after: filter for messages after a date
  • before: filter for messages before a date

Todo

  • Allow per-URL lookups and other filter options
  • Add pagination to the lookup endpoints
  • Add an "all" lookup endpoint that allows you to see all request types
  • Make DB layer abstracted
1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.1.0

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