inspector-proxy
Advanced tools
Comparing version 1.1.0 to 1.2.0
1.1.0 / 2017-09-21 | ||
================== | ||
* feat: add debug module | ||
* Update README.md | ||
1.0.0 / 2017-09-13 | ||
@@ -3,0 +9,0 @@ ================== |
88
index.js
@@ -6,7 +6,7 @@ 'use strict'; | ||
const urllib = require('urllib'); | ||
const co = require('co'); | ||
const assert = require('assert'); | ||
const EventEmitter = require('events').EventEmitter; | ||
const KEY = '__ws_proxy__'; | ||
const linkPrefix = 'chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:'; | ||
const linkPrefix = | ||
'chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:'; | ||
@@ -18,3 +18,3 @@ module.exports = class InterceptorProxy extends EventEmitter { | ||
assert(port, 'proxy port is needed!'); | ||
this.timeout; | ||
this.timeout = null; | ||
this.silent = !!options.silent; | ||
@@ -33,43 +33,49 @@ this.attached = false; | ||
this.debugPort = debugPort; | ||
return co.call(this, function* () { | ||
yield this.end(); | ||
return this.end() | ||
.then(() => { | ||
this.watchingInspect(); | ||
return new Promise(resolve => this.once('attached', resolve)); | ||
}) | ||
.then(() => | ||
this.proxy.createProxy({ | ||
forwardPort: this.debugPort, | ||
interceptor: { | ||
client: chunk => { | ||
if ( | ||
!this.inspectInfo || | ||
chunk[0] !== 0x47 || // G | ||
chunk[1] !== 0x45 || // E | ||
chunk[2] !== 0x54 || // T | ||
chunk[3] !== 0x20 // space | ||
) { | ||
return; | ||
} | ||
this.watchingInspect(); | ||
const content = chunk.toString(); | ||
const hasKey = content.includes(KEY); | ||
debug('request %s', chunk); | ||
// wait for inspectInfo | ||
yield new Promise(resolve => | ||
this.once('attached', resolve) | ||
); | ||
// remind user do not attach again with other client | ||
if ( | ||
(hasKey || content.includes(this.inspectInfo.id)) && | ||
!this.inspectInfo.webSocketDebuggerUrl | ||
) { | ||
debug('inspectInfo %o', this.inspectInfo); | ||
console.warn( | ||
"Debugger has been attached, can't attach by other client" | ||
); | ||
} | ||
yield this.proxy.createProxy({ | ||
forwardPort: this.debugPort, | ||
interceptor: { | ||
client: chunk => { | ||
if ( | ||
!this.inspectInfo || | ||
chunk[0] !== 0x47 || // G | ||
chunk[1] !== 0x45 || // E | ||
chunk[2] !== 0x54 || // T | ||
chunk[3] !== 0x20 // space | ||
) { | ||
return; | ||
} | ||
const content = chunk.toString(); | ||
const hasKey = content.includes(KEY); | ||
// remind user do not attach again with other client | ||
if ((hasKey || content.includes(this.inspectInfo.id)) && !this.inspectInfo.webSocketDebuggerUrl) { | ||
console.warn('Debugger has been attached, can\'t attach by other client'); | ||
} | ||
// replace key to websocket id | ||
if (hasKey) { | ||
debug('debugger attach request: %s', chunk); | ||
return content.replace(KEY, this.inspectInfo.id); | ||
} | ||
// replace key to websocket id | ||
if (hasKey) { | ||
debug('debugger attach request: %s', chunk); | ||
return content.replace(KEY, this.inspectInfo.id); | ||
} | ||
}, | ||
server: chunk => { | ||
debug('response %s', chunk); | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}) | ||
); | ||
} | ||
@@ -110,3 +116,3 @@ | ||
this.attached = true; | ||
this.emit('attached', this.inspectInfo = data); | ||
this.emit('attached', (this.inspectInfo = data)); | ||
this.watchingInspect(1000); | ||
@@ -113,0 +119,0 @@ } |
{ | ||
"name": "inspector-proxy", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "node inspector proxy", | ||
@@ -8,5 +8,6 @@ "bin": { | ||
}, | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"dependencies": { | ||
"cfork": "^1.6.1", | ||
"co": "^4.6.0", | ||
"debug": "^3.0.1", | ||
@@ -13,0 +14,0 @@ "tcp-proxy.js": "^1.0.5", |
@@ -78,2 +78,27 @@ # inspector-proxy | ||
## Log Explanation | ||
```bash | ||
# inspector server opened | ||
9229 opened | ||
# inspector server closed | ||
9229 closed | ||
# inspector has been attached | ||
Debugger attached | ||
``` | ||
## Debug log | ||
```bash | ||
$ DEBUG=*-proxy inspector-proxy ./test.js | ||
``` | ||
## License | ||
MIT | ||
--- | ||
![](./screen.gif) |
10926
4
6
199
104