Code Monkey home page Code Monkey logo

everybody-needs-a-404's Introduction

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.

everybody-needs-a-404's People

Contributors

distributedlife avatar rboucher-tw avatar

Stargazers

 avatar

Watchers

 avatar  avatar

everybody-needs-a-404's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.