Skip to content

Instantly share code, notes, and snippets.

@iamedu
Created June 9, 2015 04:45
Show Gist options
  • Save iamedu/2eb54e8be120756e09c2 to your computer and use it in GitHub Desktop.
Save iamedu/2eb54e8be120756e09c2 to your computer and use it in GitHub Desktop.
script.js
var http = require('http'),
httpProxy = require('http-proxy'),
tamper = require('tamper');
var host = 'localhost:4242';
var proxy = httpProxy.createProxyServer({target:'https://' + host});
var crossdomain = '<?xml version="1.0"?> <!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd"> <cross-domain-policy> <site-control permitted-cross-domain-policies="all"/> <allow-access-from domain="*" secure="false"/> <allow-http-request-headers-from domain="*" headers="*" secure="false"/> </cross-domain-policy>';
var clientaccesspolicy = '<?xml version="1.0" encoding="utf-8"?> <access-policy> <cross-domain-access> <!-- Silverlight 3 or higher requires the http-request-headers attribute. --> <policy> <allow-from http-request-headers="*"> <domain uri="http://*" /> <domain uri="https://*" /> </allow-from> <grant-to> <resource path="/" include-subpaths="true"/> </grant-to> </policy> </cross-domain-access> </access-policy>';
var t = tamper(function(req, res) {
return function (body) {
console.log(body);
return body;
};
});
http.createServer(function (req, res) {
req.headers.host = host;
t(req, res, function () {
if(req.url == '/hola') {
res.write('HOLA MUNDO');
res.end();
} else if(req.url.indexOf('/crossdomain.xml') == 0) {
res.write(crossdomain);
res.end();
} else if(req.url.indexOf('/clientaccesspolicy.xml') == 0) {
res.write(clientaccesspolicy);
res.end();
} else {
proxy.web(req,res);
}
});
}).listen(process.env.PORT || 4200);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment