http-stub

2.0.0 • Public • Published

Create an instance of http server that catches all requests to a given host.

This is useful for tests.

Install

npm i http-stub

Usage

var HttpStub = require('http-stub');
var stub = HttpStub('google.com');

stub.on('request', function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World');
}).on('listening', function () {
  //it catchs all request to the given domain.
  request.get('https://google.com', function (err, resp, body) {
    assert.equal(body, 'Hello World');
  });
});

Mount an express application:

var HttpStub = require('http-stub');

var express = require('express');
var app = express();
app.get('/bo', function (req, res) {
  res.send('hello');
});

var stub = HttpStub('google.com');

stub.on('request', app);

License

MIT 2015 - José F. Romaniello

Readme

Keywords

none

Package Sidebar

Install

npm i http-stub

Weekly Downloads

1

Version

2.0.0

License

MIT

Unpacked Size

12.4 kB

Total Files

9

Last publish

Collaborators

  • jfromaniello