Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/binocarlos/log-socket
tcp proxy socket that dumps everything through it to console.log
https://github.com/binocarlos/log-socket
Last synced: 11 days ago
JSON representation
tcp proxy socket that dumps everything through it to console.log
- Host: GitHub
- URL: https://github.com/binocarlos/log-socket
- Owner: binocarlos
- Created: 2014-08-10T15:21:12.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-08-10T16:00:32.000Z (over 10 years ago)
- Last Synced: 2024-08-11T08:30:07.105Z (3 months ago)
- Language: JavaScript
- Size: 125 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## log-socket
tcp proxy socket that dumps everything through it to console.log - useful for debugging HTTP servers
## install
```
$ npm install log-socket
```## usage
```js
var http = require('http')
var logsocket = require('logsocket')var server = http.createServer(function(req, res){
res.setHeader('x-test', 10)
res.end('hello')
})// redirect everything to this backend socket
var proxy = logsocket(8081, '127.0.0.1')// Request data
proxy.on('input', function(chunk, enc){
console.log(chunk.toString())
})// Response data
proxy.on('output', function(chunk, enc){
console.log(chunk.toString())
})server.listen(8081)
proxy.listen(8080)
```If you then curl to the logsocket - you will get a response from the backend HTTP server and the logsocket will dump all the traffic going through it
```
$ curl -L http://127.0.0.1:8080
```## api
#### `var proxy = logsocket(port, [address, opts])`
Return a tcp socket that will proxy traffic back to address:port - the default for address is '127.0.0.1'
Opts are passed into `new net.Socket(opts)`
## events
#### `proxy.on('input', function(chunk, enc){})`
Called when data is recieved by the socket
#### `proxy.on('output', function(chunk, enc){})`
Called when data is sent by the socket
## license
MIT