1.7.0 • Published 9 years ago

everybody-needs-a-404 v1.7.0

Weekly downloads
1
License
BSD-2-Clause
Repository
github
Last release
9 years ago

Everybody needs a 404

A simple web proxy that lets you either return a status code for all requests or alter the response.

I use when testing out specific scenarios on mobile applications. I point the mobile app at this proxy, the proxy forwards the request, the proxy modifies the response before responding itself.

How to return a status code.

http://localhost:3000/setMode/404

Now all responses return 404.

http://localhost:3000/setMode/200

Behaviour returns to normal

How to alter the response

var _  = require('lodash');
function filterOutASpecificRecord (body) {
  var json = JSON.parse(body);

  json.records = _.reject(json.records, {id: 37});

  return json;
}

var proxy = require('everybody-needs-a-404');
proxy.modify('/records', filterOutASpecificRecord);
proxy.go('http://the-original-service.com:23423');

Now set the mode to altered and we are away.

http://localhost:3000/setMode/altered

How to rewrite a url

var _  = require('lodash');
function newUrl (req) {
  return "/newPath";
}

var proxy = require('everybody-needs-a-404');
proxy.rewriteUrl('/records/:id', newUrl);
proxy.go('http://the-original-service.com:23423');

Now set the mode to altered and we are away.

http://localhost:3000/setMode/altered

How to rewrite a url AND change the respond

var _  = require('lodash');
function newUrl (req) {
  return "/newPath";
}

function filterOutASpecificRecord (body) {
  var json = JSON.parse(body);

  json.records = _.reject(json.records, {id: 37});

  return json;
}

var proxy = require('everybody-needs-a-404');
proxy.rewriteUrl('/records/:id', newUrl, filterOutASpecificRecord);
proxy.go('http://the-original-service.com:23423');

Now set the mode to altered and we are away.

http://localhost:3000/setMode/altered

How to slow down responses

http://localhost:3000/setDelay/1000

Now all requests will pause for a second before responding

http://localhost:3000/setDelay/0

Behaviour returns to normal.

What's with the name

Everybody Needs a 303. If the link doesn't work. Google it.

1.7.0

9 years ago

1.6.0

9 years ago

1.5.0

9 years ago

1.4.0

9 years ago

1.3.0

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago