Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/JohanObrink/intercept-proxy
https://github.com/JohanObrink/intercept-proxy
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/JohanObrink/intercept-proxy
- Owner: JohanObrink
- Created: 2012-08-24T07:36:40.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2015-03-22T03:54:10.000Z (over 9 years ago)
- Last Synced: 2024-04-25T18:42:00.851Z (8 months ago)
- Language: JavaScript
- Size: 197 KB
- Stars: 16
- Watchers: 3
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#Intercept Proxy [![Build Status](https://secure.travis-ci.org/JohanObrink/intercept-proxy.png?branch=master)](http://travis-ci.org/JohanObrink/intercept-proxy)
-
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 withnpm 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 :)