0.1.4 • Published 10 years ago

xhr2proxy v0.1.4

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

##Description

HTTP/HTTPS proxy plugin of connect/express for XHR(XMLHTTPRequest) with referer restriction and appending Access-Control-Allow-Origin for cross domain XHR2 Based on cdproxy by macchadogj(thanks)

##Installation

$ npm install xhr2proxy

##Usage

###basic

var xhr2proxy = require('xhr2proxy');

connect()
	.use(xhr2proxy({prefix:'myprefix'})) //proxy by default.
	.use(function ( req, res ) {
	res.end("Hello from Connect!");
}).listen(8000);

//var xhr=new XMLHttpRequest();
//xhr.open('get','http://localhost:8000/myprefix/http://myremote.server',false);
//xhr.send();

##basic(express)

var xhr2proxy = require('xhr2proxy');
var app=require('express').createServer();
app.use(xhr2proxy());
app.listen(8000);

//var xhr=new XMLHttpRequest();
//xhr.open('get','http://localhost:8000/prefix/http://myremote.server',false);
//xhr.send();

###Appending Access-Control-Allow-Origin to response headers

It allows XMLHttpRequest level2 to connect with non supported servers from outside of the domains which runs this script.

var xhr2proxy = require('xhr2proxy');

connect()
	.use(xhr2proxy({prefix:'myprefix',acao:'*'}) //Append [Access-Control-Allow-Origin: *]
	.use(function ( req, res ) {
	res.end("Hello from Connect!");
}).listen(8000);

//var xhr=new XMLHttpRequest();
//xhr.open('get','http://anywhrere:8000/myprefix/http://myremote.server',false);
//xhr.send();

###referer restriction

prevent out-site using by referer restriction.CAUTION:It cannot recognize fake headers.

var xhr2proxy = require('xhr2proxy');

connect()
	.use(xhr2proxy({prefix:'myprefix',referer:/^http:\/\/localhost/})) //deny if referer isnot http://localhost...
	.use(function ( req, res ) {
	res.end("Hello from Connect!");
}).listen(8000);

//var xhr=new XMLHttpRequest();
//xhr.open(''get',http://localhost:8000/myprefix/http://myremote.server',false);
//xhr.send();
//with referer http://localhost:8000/anywhere.html

###other options

suppressHostNameOnRequest(bool)

default or false:
	GET http://localhost/path HTTP/1.0
				.
				.

true:
	GET /path HTTP/1.0
				.
				.

##Running unit tests

$npm test

##History

0.1.0: Adds option suppressHostNameOnRequest.

0.1.4

10 years ago

0.1.2

10 years ago

0.1.1

11 years ago

0.1.0

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago