Restore proxy server
This commit is contained in:
parent
cd92f1c0cc
commit
d96831de19
4 changed files with 41 additions and 5 deletions
30
socketIO_client/tests/proxy.js
Normal file
30
socketIO_client/tests/proxy.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
var proxy = require('http-proxy').createProxyServer({
|
||||
target: {host: 'localhost', port: 9000}
|
||||
});
|
||||
var server = require('http').createServer(function(req, res) {
|
||||
console.log('[REQUEST.%s] %s', req.method, req.url);
|
||||
console.log(req['headers']);
|
||||
if (req.method == 'POST') {
|
||||
var body = '';
|
||||
req.on('data', function (data) {
|
||||
body += data;
|
||||
});
|
||||
req.on('end', function () {
|
||||
print_body('[REQUEST.BODY] ', body);
|
||||
});
|
||||
}
|
||||
var write = res.write;
|
||||
res.write = function(data) {
|
||||
print_body('[RESPONSE.BODY] ', data);
|
||||
write.call(res, data);
|
||||
}
|
||||
proxy.web(req, res);
|
||||
});
|
||||
function print_body(header, body) {
|
||||
var text = String(body);
|
||||
console.log(header + text);
|
||||
for (var i = 0; i < text.length; i++) {
|
||||
console.log('body[%s] = %s = %s', i, text[i], text.charCodeAt(i));
|
||||
}
|
||||
}
|
||||
server.listen(8000);
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// DEBUG=* node serve.js
|
||||
|
||||
var app = require('http').createServer(serve).listen(8000);
|
||||
var app = require('http').createServer(serve).listen(9000);
|
||||
var io = require('socket.io')(app);
|
||||
var fs = require('fs');
|
||||
var PAYLOAD = {'xxx': 'yyy'};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue