... util = require('util');
var host = { address:'127.0.0.1', port:{ proxy:1337, server:1338
}, serverUri:function() { return util.format('http://%s:%d', this.address, this.port.server); }, proxyUri:function() { return util.format('http://%s:%d', this.address, this.port.proxy); } };
// // Create a proxy server with custom application logic // var proxy = httpProxy.createProxyServer({});
// // Create your custom server and just call `proxy.web()` to proxy // a web request to the target passed in the options // also you can use `proxy.ws()` to proxy a websockets request // var server = http.createServer(function(req, res) { // You can define here your custom logic to handle the request // and then proxy the request. console.log('Request', JSON.stringify(req.headers, true, 2));
req.on('data', function (data) { console.dir( data.toString() ); });
proxy.web(req, res, { target: host.proxyUri() } ); });
proxy.on('proxyRes', function (proxyRes, req, res) { proxyRes.on('data', function (data) { console.dir( data.toString() ); });
console.log('Response', JSON.stringify(proxyRes.headers, true, 2)); });
///////////// SOAP SERVICE ///////////////////////////////// function MyTestService(){ } MyTestService.prototype.test1 = function(myArg1, myArg2){ console.log( "test1 ", "" + myArg1, "" + myArg2);
return myArg1 + myArg2; };
var soapServer = new soap.SoapServer(); var soapService = soapServer.addService('testService', new MyTestService());
/////// PROXY START console.log("Proxy listening on port: ", host.port.proxy); server.listen(host.port.proxy);
////// SOAP START soapServer.listen(host.port.server, host.address);
console.log('Server running at ', host.port.server); console.log("wsdl: ",host.proxyUri(), '/testService?wsdl'); |