forked from node-inspector/node-inspector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (49 loc) · 1.75 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Public API for node-inspector embedders
var url = require('url');
var path = require('path');
exports.buildInspectorUrl = buildInspectorUrl;
exports.buildWebSocketUrl = buildWebSocketUrl;
/**
* Build a URL for loading inspector UI in the browser.
* @param {string|undefined} inspectorHost as configured via --web-host
* @param {number} inspectorPort as configured via --web-port
* @param {number} debugPort as configured via --debug in the debugged app
* @param {number} isHttps as configured via --ssl-cert and --ssl-key in the debugged app
*/
function buildInspectorUrl(inspectorHost, inspectorPort, debugPort, isHttps) {
var host = inspectorHost == '0.0.0.0' ? '127.0.0.1' : inspectorHost;
var port = inspectorPort;
var protocol = isHttps ? 'https' : 'http';
var isUnixSocket = !/^\d+$/.test(port);
if (isUnixSocket) {
host = path.resolve(__dirname, inspectorPort);
port = null;
protocol = 'unix';
}
var parts = {
protocol: protocol,
hostname: host,
port: port,
pathname: '/',
search: '?port=' + debugPort
};
return url.format(parts);
}
/**
* Build a URL for the WebSocket endpoint.
* @param {string|undefined} inspectorHost as configured via --web-host
* @param {number} inspectorPort as configured via --web-port
* @param {number} debugPort as configured via --debug in the debugged app
* @param {number} isHttps as configured via --ssl-cert and --ssl-key in the debugged app
*/
function buildWebSocketUrl(inspectorHost, inspectorPort, debugPort, isSecure) {
var parts = {
protocol: isSecure ? 'wss:' : 'ws:',
hostname: inspectorHost == '0.0.0.0' ? '127.0.0.1' : inspectorHost,
port: inspectorPort,
pathname: '/',
search: '?port=' + debugPort,
slashes: true
};
return url.format(parts);
}