Giter Club home page Giter Club logo

intercept-proxy's Introduction

#Intercept Proxy Build Status

A lite-weight proxy for exposing a remote site through localhost and replace select resources with local versions for testing and development purposes.

##Install

npm install intercept-proxy

##CLI To use command line, you must first install package with

npm install -g intercept-proxy

This is just done once. Then you can call:

intercept-proxy myremote -h myremotesite.com -p 3000
cd myremote
npm install
npm start

...and the site will runat http://localhost:3000 and point to myremotesite.com

##Usage By pointing the proxy server at a url and running the app, you can surf the targeted site through localhost:

var proxy = require('intercept-proxy');
var server = proxy.createServer('knowyourmeme.com');
server.listen(1337, function() {
  console.log('Proxy: ' + server.host + ' listening on http://localhost:' + server.port);
});

or with more options:

proxy.createServer({
  host: 'knowyourmeme.com',
  methods: 'GET,POST',           // will intercept GET and POST but not PUT and DELETE
  supressQuery: true             // remove query parameters from url when looking for local file
});

##Intercepting with locals By adding files to /local/[path], those files will replace the ones from the original site. Only GET requests will be intercepted by default.

/js/main.js can be replaced by creating /local/js/main.js

###Controlling headers for local intercepts intercept-proxy adds headers by default for common resource extensions such as css, js, html, aspx, php. If you need to control the headers, add a file called headers.json in the folder under local. All properties in the json object will be added as headers. If a default header is specified in headers.json, this will be overridden.

##Intercepting with handlers Calls can also be intercepted using handlers. A handler can be registered with just path or path and verbs

// register handler which responds to all calls to /foo/bar
proxy.addHandler('/foo/bar', function(req, res) {
  res.end('foo');
});

//register handler which responds to POSTs and PUTs to /foo/bar
proxy.addHandler('/foo/bar', 'POST,PUT', function(req, res) {
  res.end('foo');
});

//remove handler for all verbs in requests for /foo/bar
proxy.removeHandler('/foo/bar');

//remove handler for GET and DELETE in requests for /foo/bar
proxy.removeHandler('/foo/bar', 'GET,DELETE');

##Why? Beacuse I needed it for a project :)

intercept-proxy's People

Contributors

johanobrink avatar ullmark avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

intercept-proxy's Issues

Ignore request parameters?

Hi,

many thanks for your very interesting proxy implementation.
I've got one small question:
Our application server appends a URL parameter with last modified timestamp
/.../path/to/myJS.js?noCache=1410955520
to each request, to prevent the browser from caching outdated JS files.

This seems to hinder intercept-proxy to map local files to remote files.
Is it possible to make intercept-proxy ignore these URL parameters?

Many thanks in advance,
Sascha.

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.