Home

Awesome

  ___   _     _    
 / / \ \ \_/ \ \_/ 
 \_\_/ /_/ \  |_|  

an HTTP proxy to aid
in web development

feature set, implemented as plugins:

notes

This proxy doesn't handle HTTPS requests.
If you have a simple solution for this I'd love to hear it.

how to install

[sudo] npm install -g oxy

how to use

oxy <path_to_config_file>

configuring oxy

The configuration file isn't strict JSON any more. It is now eval'ed so comments and functions can now be defined.

A sample configuration follows:

{
    port: 8080, // local proxy server port, defaulting to 8080

    logLevel: 1, //0=quiet, 1=log changed requests, 2=log all requests

    monochrome: false, // false is default. set true do disable console colors

    replaceWithFile: [
        { // regular replace URL with local file
            from: "http://www.google.com/asd.js",
            to:   "/home/user/asd.js",
            mime: "text/javascript" // this is asserted automatically from the js extension on the to field
        },
        { // regular replace URL with file (regexp)
            from: /http:\/\/aaa\.bbb\.com/,
            to:   '/home/user/clown.png'
        }
        { // replace URL by local file if having extension...
            from: function(u) {
                var t = u.split('.');
                var ext = t.pop().toLowerCase();
                if (['jpeg', 'jpg', 'png', 'gif'].indexOf(ext) !== -1) {
                    return '/home/user/image.jpg';
                }
            }
        },
    ],
    replaceWithUrl: [
        { // regular replace URL with other URL
            from: "http://www.asd.com/a.jpg",
            to:   "http://localhost/a.jpg"
        },
        { // replaces URLs having text '/asd/', changing host 'x.com' to 'y.com'
            from: function(u) {
                if (u.indexOf('/asd/') === -1) { return; }
                return u.replace('x.com', 'y.com');
            }
        },
        { // regular URL replace (partial)
            from: 'http://aaa.com/Bundles/Video',
            to:   'http://localhost/Bundles/Video',
            partialMatch: true
        },
        { // replace URL if having extension...
            from: function(u) {
                var t = u.split('.');
                var ext = t.pop().toLowerCase();
                if (['jpeg', 'jpg', 'png', 'gif'].indexOf(ext) !== -1) {
                    return 'http://localhost/image.jpg';
                }
            }
        },
        { // log files not handled yet which have ext js
          from: function(u) {
            if (u.indexOf('.js') === -1) { return; }
            console.log(u);
          }
        }
    ]
}

plugin interface

Everything in the lib folder besides index.js are plugins.

Plugins are loaded only if mentioned in the configuration (as keys).

A plugin is a function with the following interface:

function(req, res, cfgAll, log, warn, error)

req and res are respectively the request and response HTTP objects.
cfgAll is the parsed JS for the loaded configuration file.
log, warn and error are functions passed for sharing console output methods between plugins (this should be revised, kinda ugly).

roadmap

changelog

0.0.3 Monday, the 25th of November 2013

0.0.2 Monday, the 25th of November 2013