@modern-js/plugin-proxy 1.21.5 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -8
- package/dist/js/modern/index.js +0 -6
- package/dist/js/modern/utils/createProxyRule.js +2 -11
- package/dist/js/modern/utils/execSync.js +0 -3
- package/dist/js/modern/utils/macCAManager.js +4 -7
- package/dist/js/modern/utils/macProxyManager.js +2 -5
- package/dist/js/modern/utils/whistleProxy.js +2 -13
- package/dist/js/node/index.js +0 -12
- package/dist/js/node/utils/createProxyRule.js +2 -18
- package/dist/js/node/utils/execSync.js +0 -4
- package/dist/js/node/utils/macCAManager.js +4 -26
- package/dist/js/node/utils/macProxyManager.js +2 -11
- package/dist/js/node/utils/whistleProxy.js +2 -22
- package/dist/types/index.d.ts +0 -2
- package/package.json +7 -30
package/CHANGELOG.md
CHANGED
|
@@ -1,22 +1,46 @@
|
|
|
1
1
|
# @modern-js/plugin-proxy
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 2.0.0-beta.1
|
|
4
4
|
|
|
5
|
-
###
|
|
6
|
-
|
|
7
|
-
- @modern-js/utils@1.21.5
|
|
5
|
+
### Major Changes
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
- dda38c9: chore: v2
|
|
10
8
|
|
|
11
9
|
### Patch Changes
|
|
12
10
|
|
|
13
|
-
-
|
|
11
|
+
- Updated dependencies [92f0ead]
|
|
12
|
+
- Updated dependencies [edd1cfb1af]
|
|
13
|
+
- Updated dependencies [cc971eabfc]
|
|
14
|
+
- Updated dependencies [5b9049f]
|
|
15
|
+
- Updated dependencies [92004d1]
|
|
16
|
+
- Updated dependencies [b8bbe036c7]
|
|
17
|
+
- Updated dependencies [d5a31df781]
|
|
18
|
+
- Updated dependencies [dda38c9]
|
|
19
|
+
- Updated dependencies [3bbea92b2a]
|
|
20
|
+
- Updated dependencies [abf3421]
|
|
21
|
+
- Updated dependencies [543be9558e]
|
|
22
|
+
- Updated dependencies [14b712d]
|
|
23
|
+
- @modern-js/utils@2.0.0-beta.1
|
|
24
|
+
|
|
25
|
+
## 2.0.0-beta.0
|
|
26
|
+
|
|
27
|
+
### Major Changes
|
|
14
28
|
|
|
15
|
-
|
|
29
|
+
- dda38c9: chore: v2
|
|
16
30
|
|
|
17
31
|
### Patch Changes
|
|
18
32
|
|
|
19
|
-
-
|
|
33
|
+
- Updated dependencies [edd1cfb1a]
|
|
34
|
+
- Updated dependencies [cc971eabf]
|
|
35
|
+
- Updated dependencies [5b9049f]
|
|
36
|
+
- Updated dependencies [b8bbe036c]
|
|
37
|
+
- Updated dependencies [d5a31df78]
|
|
38
|
+
- Updated dependencies [dda38c9]
|
|
39
|
+
- Updated dependencies [3bbea92b2]
|
|
40
|
+
- Updated dependencies [abf3421]
|
|
41
|
+
- Updated dependencies [543be95]
|
|
42
|
+
- Updated dependencies [14b712d]
|
|
43
|
+
- @modern-js/utils@2.0.0-beta.0
|
|
20
44
|
|
|
21
45
|
## 1.21.2
|
|
22
46
|
|
package/dist/js/modern/index.js
CHANGED
|
@@ -9,7 +9,6 @@ export default (() => {
|
|
|
9
9
|
validateSchema() {
|
|
10
10
|
return PLUGIN_SCHEMAS['@modern-js/plugin-proxy'];
|
|
11
11
|
},
|
|
12
|
-
|
|
13
12
|
async afterDev() {
|
|
14
13
|
const {
|
|
15
14
|
dev
|
|
@@ -17,11 +16,9 @@ export default (() => {
|
|
|
17
16
|
const {
|
|
18
17
|
internalDirectory
|
|
19
18
|
} = api.useAppContext();
|
|
20
|
-
|
|
21
19
|
if (!(dev !== null && dev !== void 0 && dev.proxy)) {
|
|
22
20
|
return;
|
|
23
21
|
}
|
|
24
|
-
|
|
25
22
|
const rule = createProxyRule(internalDirectory, dev.proxy);
|
|
26
23
|
proxyServer = new WhistleProxy({
|
|
27
24
|
port: 8899,
|
|
@@ -29,14 +26,11 @@ export default (() => {
|
|
|
29
26
|
});
|
|
30
27
|
await proxyServer.start();
|
|
31
28
|
},
|
|
32
|
-
|
|
33
29
|
beforeExit() {
|
|
34
30
|
var _proxyServer;
|
|
35
|
-
|
|
36
31
|
// terminate whistle proxy
|
|
37
32
|
(_proxyServer = proxyServer) === null || _proxyServer === void 0 ? void 0 : _proxyServer.close();
|
|
38
33
|
}
|
|
39
|
-
|
|
40
34
|
})
|
|
41
35
|
};
|
|
42
36
|
});
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { logger, fs } from '@modern-js/utils';
|
|
3
|
-
|
|
4
3
|
const createWhistleProxyRule = (ruleDirectory, rules) => {
|
|
5
4
|
const dest = path.resolve(ruleDirectory, 'proxy.rule.js');
|
|
6
5
|
let code = `/.*/ enable://intercept\n`;
|
|
7
|
-
|
|
8
6
|
for (const rule of rules) {
|
|
9
7
|
const {
|
|
10
8
|
pattern,
|
|
@@ -12,34 +10,27 @@ const createWhistleProxyRule = (ruleDirectory, rules) => {
|
|
|
12
10
|
} = rule;
|
|
13
11
|
code += `${pattern} ${target}\n`;
|
|
14
12
|
}
|
|
15
|
-
|
|
16
13
|
fs.outputFileSync(dest, `exports.name = 'modernjs proxy rule';\nexports.rules = \`${code}\`;`);
|
|
17
14
|
return dest;
|
|
18
15
|
};
|
|
19
|
-
|
|
20
16
|
export const createProxyRule = (appDirectory, proxyOptions) => {
|
|
21
17
|
const rules = [];
|
|
22
|
-
|
|
23
18
|
if (proxyOptions && typeof proxyOptions === 'string') {
|
|
24
19
|
return proxyOptions;
|
|
25
20
|
}
|
|
26
|
-
|
|
27
21
|
if (typeof proxyOptions === 'object') {
|
|
28
22
|
for (const pattern of Object.keys(proxyOptions)) {
|
|
29
23
|
const target = proxyOptions[pattern];
|
|
30
|
-
|
|
31
24
|
if (!target || typeof target !== 'string') {
|
|
32
|
-
logger.error(`dev.proxy.${pattern} value should be string type`);
|
|
33
|
-
|
|
25
|
+
logger.error(`dev.proxy.${pattern} value should be string type`);
|
|
26
|
+
// eslint-disable-next-line no-process-exit
|
|
34
27
|
process.exit(1);
|
|
35
28
|
}
|
|
36
|
-
|
|
37
29
|
rules.push({
|
|
38
30
|
pattern,
|
|
39
31
|
target
|
|
40
32
|
});
|
|
41
33
|
}
|
|
42
34
|
}
|
|
43
|
-
|
|
44
35
|
return createWhistleProxyRule(appDirectory, rules);
|
|
45
36
|
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { execSync as nodeExecSync } from 'child_process';
|
|
2
|
-
|
|
3
2
|
function execSync(cmd) {
|
|
4
3
|
let stdout;
|
|
5
4
|
let status = 0;
|
|
6
|
-
|
|
7
5
|
try {
|
|
8
6
|
stdout = nodeExecSync(cmd);
|
|
9
7
|
} catch (err) {
|
|
@@ -18,5 +16,4 @@ function execSync(cmd) {
|
|
|
18
16
|
status
|
|
19
17
|
};
|
|
20
18
|
}
|
|
21
|
-
|
|
22
19
|
export default execSync;
|
|
@@ -10,29 +10,27 @@ export const trustRootCA = () => {
|
|
|
10
10
|
const {
|
|
11
11
|
status
|
|
12
12
|
} = execSync(`sudo security add-trusted-cert -d -k /Library/Keychains/System.keychain ${defaultRootCA}`);
|
|
13
|
-
|
|
14
13
|
if (status === 0) {
|
|
15
14
|
logger.info('Root CA install, you are ready to intercept the https now');
|
|
16
15
|
} else {
|
|
17
16
|
logger.info('Failed to trust the root CA, please trust it manually');
|
|
18
17
|
}
|
|
19
|
-
}; // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
20
|
-
|
|
21
|
-
const isRootCATrusted = () => {// current empty
|
|
22
18
|
};
|
|
23
19
|
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
21
|
+
const isRootCATrusted = () => {
|
|
22
|
+
// current empty
|
|
23
|
+
};
|
|
24
24
|
export const isRootCAExists = () => {
|
|
25
25
|
if (fs.existsSync(defaultRootCA)) {
|
|
26
26
|
return true;
|
|
27
27
|
}
|
|
28
|
-
|
|
29
28
|
return false;
|
|
30
29
|
};
|
|
31
30
|
export const generateRootCA = () => new Promise((resolve, reject) => {
|
|
32
31
|
if (fs.existsSync(defaultRootCA)) {
|
|
33
32
|
fs.removeSync(defaultRootCA);
|
|
34
33
|
}
|
|
35
|
-
|
|
36
34
|
fs.ensureDirSync(defaultCertDir);
|
|
37
35
|
const stream = fs.createWriteStream(defaultRootCA);
|
|
38
36
|
http.get('http://localhost:8899/cgi-bin/rootca', response => {
|
|
@@ -44,7 +42,6 @@ export const generateRootCA = () => new Promise((resolve, reject) => {
|
|
|
44
42
|
});
|
|
45
43
|
}).on('error', err => {
|
|
46
44
|
fs.unlink(defaultRootCA); // Delete the file
|
|
47
|
-
|
|
48
45
|
reject(err);
|
|
49
46
|
});
|
|
50
47
|
});
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
import execSync from "./execSync";
|
|
2
2
|
const networkTypes = ['Ethernet', 'Thunderbolt Ethernet', 'Wi-Fi'];
|
|
3
|
-
|
|
4
3
|
const getNetworkType = () => {
|
|
5
4
|
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
6
5
|
for (let i = 0; i < networkTypes.length; i++) {
|
|
7
6
|
const type = networkTypes[i];
|
|
8
7
|
const result = execSync(`networksetup -getwebproxy ${type}`);
|
|
9
|
-
|
|
10
8
|
if (result.status === 0) {
|
|
11
9
|
return type;
|
|
12
10
|
}
|
|
13
11
|
}
|
|
14
|
-
|
|
15
12
|
throw new Error('Unknown network type');
|
|
16
13
|
};
|
|
17
|
-
|
|
18
14
|
export const enableGlobalProxy = (ip, port) => {
|
|
19
|
-
const networkType = getNetworkType();
|
|
15
|
+
const networkType = getNetworkType();
|
|
20
16
|
|
|
17
|
+
// && networksetup -setproxybypassdomains ${networkType} localhost localhost
|
|
21
18
|
execSync(`networksetup -setwebproxy ${networkType} ${ip} ${port}`);
|
|
22
19
|
execSync(`networksetup -setsecurewebproxy ${networkType} ${ip} ${port}`);
|
|
23
20
|
};
|
|
@@ -1,33 +1,25 @@
|
|
|
1
1
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
-
|
|
3
2
|
import path from 'path';
|
|
4
3
|
import { logger } from '@modern-js/utils';
|
|
5
4
|
import execSync from "./execSync";
|
|
6
5
|
import { isRootCAExists, generateRootCA, defaultRootCA, trustRootCA } from "./macCAManager";
|
|
7
|
-
|
|
8
6
|
const {
|
|
9
7
|
disableGlobalProxy,
|
|
10
8
|
enableGlobalProxy
|
|
11
9
|
} = require("./macProxyManager");
|
|
12
|
-
|
|
13
10
|
export default class WhistleProxy {
|
|
14
11
|
constructor(config) {
|
|
15
12
|
_defineProperty(this, "rule", void 0);
|
|
16
|
-
|
|
17
13
|
_defineProperty(this, "port", void 0);
|
|
18
|
-
|
|
19
14
|
_defineProperty(this, "bin", void 0);
|
|
20
|
-
|
|
21
15
|
_defineProperty(this, "certDir", void 0);
|
|
22
|
-
|
|
23
16
|
this.rule = config.rule;
|
|
24
|
-
this.port = config.port;
|
|
17
|
+
this.port = config.port;
|
|
18
|
+
// unused
|
|
25
19
|
// this.mode = config.mode; // pureProxy|debug|multiEnv
|
|
26
|
-
|
|
27
20
|
this.bin = path.resolve(path.dirname(require.resolve('whistle')), 'bin/whistle.js');
|
|
28
21
|
this.certDir = path.dirname(defaultRootCA);
|
|
29
22
|
}
|
|
30
|
-
|
|
31
23
|
async installRootCA() {
|
|
32
24
|
try {
|
|
33
25
|
if (!isRootCAExists()) {
|
|
@@ -39,7 +31,6 @@ export default class WhistleProxy {
|
|
|
39
31
|
throw err;
|
|
40
32
|
}
|
|
41
33
|
}
|
|
42
|
-
|
|
43
34
|
async start() {
|
|
44
35
|
logger.info(`Starting the proxy server.....`);
|
|
45
36
|
execSync(`${this.bin} start --certDir=${this.certDir} --port=${this.port}`);
|
|
@@ -48,11 +39,9 @@ export default class WhistleProxy {
|
|
|
48
39
|
enableGlobalProxy('localhost', this.port);
|
|
49
40
|
logger.info(`Proxy Server start on localhost:${this.port}\n`);
|
|
50
41
|
}
|
|
51
|
-
|
|
52
42
|
close() {
|
|
53
43
|
execSync(`${this.bin} stop`);
|
|
54
44
|
disableGlobalProxy();
|
|
55
45
|
logger.info(`Proxy Server has been closed`);
|
|
56
46
|
}
|
|
57
|
-
|
|
58
47
|
}
|
package/dist/js/node/index.js
CHANGED
|
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _utils = require("@modern-js/utils");
|
|
9
|
-
|
|
10
8
|
var _createProxyRule = require("./utils/createProxyRule");
|
|
11
|
-
|
|
12
9
|
var _whistleProxy = _interopRequireDefault(require("./utils/whistleProxy"));
|
|
13
|
-
|
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
11
|
var _default = () => {
|
|
17
12
|
let proxyServer;
|
|
18
13
|
return {
|
|
@@ -21,7 +16,6 @@ var _default = () => {
|
|
|
21
16
|
validateSchema() {
|
|
22
17
|
return _utils.PLUGIN_SCHEMAS['@modern-js/plugin-proxy'];
|
|
23
18
|
},
|
|
24
|
-
|
|
25
19
|
async afterDev() {
|
|
26
20
|
const {
|
|
27
21
|
dev
|
|
@@ -29,11 +23,9 @@ var _default = () => {
|
|
|
29
23
|
const {
|
|
30
24
|
internalDirectory
|
|
31
25
|
} = api.useAppContext();
|
|
32
|
-
|
|
33
26
|
if (!(dev !== null && dev !== void 0 && dev.proxy)) {
|
|
34
27
|
return;
|
|
35
28
|
}
|
|
36
|
-
|
|
37
29
|
const rule = (0, _createProxyRule.createProxyRule)(internalDirectory, dev.proxy);
|
|
38
30
|
proxyServer = new _whistleProxy.default({
|
|
39
31
|
port: 8899,
|
|
@@ -41,16 +33,12 @@ var _default = () => {
|
|
|
41
33
|
});
|
|
42
34
|
await proxyServer.start();
|
|
43
35
|
},
|
|
44
|
-
|
|
45
36
|
beforeExit() {
|
|
46
37
|
var _proxyServer;
|
|
47
|
-
|
|
48
38
|
// terminate whistle proxy
|
|
49
39
|
(_proxyServer = proxyServer) === null || _proxyServer === void 0 ? void 0 : _proxyServer.close();
|
|
50
40
|
}
|
|
51
|
-
|
|
52
41
|
})
|
|
53
42
|
};
|
|
54
43
|
};
|
|
55
|
-
|
|
56
44
|
exports.default = _default;
|
|
@@ -4,18 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createProxyRule = void 0;
|
|
7
|
-
|
|
8
7
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
const createWhistleProxyRule = (ruleDirectory, rules) => {
|
|
15
11
|
const dest = _path.default.resolve(ruleDirectory, 'proxy.rule.js');
|
|
16
|
-
|
|
17
12
|
let code = `/.*/ enable://intercept\n`;
|
|
18
|
-
|
|
19
13
|
for (const rule of rules) {
|
|
20
14
|
const {
|
|
21
15
|
pattern,
|
|
@@ -23,38 +17,28 @@ const createWhistleProxyRule = (ruleDirectory, rules) => {
|
|
|
23
17
|
} = rule;
|
|
24
18
|
code += `${pattern} ${target}\n`;
|
|
25
19
|
}
|
|
26
|
-
|
|
27
20
|
_utils.fs.outputFileSync(dest, `exports.name = 'modernjs proxy rule';\nexports.rules = \`${code}\`;`);
|
|
28
|
-
|
|
29
21
|
return dest;
|
|
30
22
|
};
|
|
31
|
-
|
|
32
23
|
const createProxyRule = (appDirectory, proxyOptions) => {
|
|
33
24
|
const rules = [];
|
|
34
|
-
|
|
35
25
|
if (proxyOptions && typeof proxyOptions === 'string') {
|
|
36
26
|
return proxyOptions;
|
|
37
27
|
}
|
|
38
|
-
|
|
39
28
|
if (typeof proxyOptions === 'object') {
|
|
40
29
|
for (const pattern of Object.keys(proxyOptions)) {
|
|
41
30
|
const target = proxyOptions[pattern];
|
|
42
|
-
|
|
43
31
|
if (!target || typeof target !== 'string') {
|
|
44
|
-
_utils.logger.error(`dev.proxy.${pattern} value should be string type`);
|
|
45
|
-
|
|
46
|
-
|
|
32
|
+
_utils.logger.error(`dev.proxy.${pattern} value should be string type`);
|
|
33
|
+
// eslint-disable-next-line no-process-exit
|
|
47
34
|
process.exit(1);
|
|
48
35
|
}
|
|
49
|
-
|
|
50
36
|
rules.push({
|
|
51
37
|
pattern,
|
|
52
38
|
target
|
|
53
39
|
});
|
|
54
40
|
}
|
|
55
41
|
}
|
|
56
|
-
|
|
57
42
|
return createWhistleProxyRule(appDirectory, rules);
|
|
58
43
|
};
|
|
59
|
-
|
|
60
44
|
exports.createProxyRule = createProxyRule;
|
|
@@ -4,13 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _child_process = require("child_process");
|
|
9
|
-
|
|
10
8
|
function execSync(cmd) {
|
|
11
9
|
let stdout;
|
|
12
10
|
let status = 0;
|
|
13
|
-
|
|
14
11
|
try {
|
|
15
12
|
stdout = (0, _child_process.execSync)(cmd);
|
|
16
13
|
} catch (err) {
|
|
@@ -25,6 +22,5 @@ function execSync(cmd) {
|
|
|
25
22
|
status
|
|
26
23
|
};
|
|
27
24
|
}
|
|
28
|
-
|
|
29
25
|
var _default = execSync;
|
|
30
26
|
exports.default = _default;
|
|
@@ -4,64 +4,45 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.trustRootCA = exports.isRootCAExists = exports.generateRootCA = exports.defaultRootCA = void 0;
|
|
7
|
-
|
|
8
7
|
var _os = _interopRequireDefault(require("os"));
|
|
9
|
-
|
|
10
8
|
var _http = _interopRequireDefault(require("http"));
|
|
11
|
-
|
|
12
9
|
var _path = _interopRequireDefault(require("path"));
|
|
13
|
-
|
|
14
10
|
var _utils = require("@modern-js/utils");
|
|
15
|
-
|
|
16
11
|
var _execSync = _interopRequireDefault(require("./execSync"));
|
|
17
|
-
|
|
18
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
13
|
const defaultCertDir = _path.default.resolve(_os.default.homedir(), './.whistle-proxy');
|
|
21
|
-
|
|
22
14
|
const defaultRootCA = _path.default.resolve(defaultCertDir, './rootCA.crt');
|
|
23
|
-
|
|
24
15
|
exports.defaultRootCA = defaultRootCA;
|
|
25
|
-
|
|
26
16
|
const trustRootCA = () => {
|
|
27
17
|
_utils.logger.info(`please type the password to trust the https certificate`);
|
|
28
|
-
|
|
29
18
|
const {
|
|
30
19
|
status
|
|
31
20
|
} = (0, _execSync.default)(`sudo security add-trusted-cert -d -k /Library/Keychains/System.keychain ${defaultRootCA}`);
|
|
32
|
-
|
|
33
21
|
if (status === 0) {
|
|
34
22
|
_utils.logger.info('Root CA install, you are ready to intercept the https now');
|
|
35
23
|
} else {
|
|
36
24
|
_utils.logger.info('Failed to trust the root CA, please trust it manually');
|
|
37
25
|
}
|
|
38
|
-
};
|
|
39
|
-
|
|
26
|
+
};
|
|
40
27
|
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
41
29
|
exports.trustRootCA = trustRootCA;
|
|
42
|
-
|
|
43
|
-
|
|
30
|
+
const isRootCATrusted = () => {
|
|
31
|
+
// current empty
|
|
44
32
|
};
|
|
45
|
-
|
|
46
33
|
const isRootCAExists = () => {
|
|
47
34
|
if (_utils.fs.existsSync(defaultRootCA)) {
|
|
48
35
|
return true;
|
|
49
36
|
}
|
|
50
|
-
|
|
51
37
|
return false;
|
|
52
38
|
};
|
|
53
|
-
|
|
54
39
|
exports.isRootCAExists = isRootCAExists;
|
|
55
|
-
|
|
56
40
|
const generateRootCA = () => new Promise((resolve, reject) => {
|
|
57
41
|
if (_utils.fs.existsSync(defaultRootCA)) {
|
|
58
42
|
_utils.fs.removeSync(defaultRootCA);
|
|
59
43
|
}
|
|
60
|
-
|
|
61
44
|
_utils.fs.ensureDirSync(defaultCertDir);
|
|
62
|
-
|
|
63
45
|
const stream = _utils.fs.createWriteStream(defaultRootCA);
|
|
64
|
-
|
|
65
46
|
_http.default.get('http://localhost:8899/cgi-bin/rootca', response => {
|
|
66
47
|
response.pipe(stream);
|
|
67
48
|
stream.on('finish', () => {
|
|
@@ -71,10 +52,7 @@ const generateRootCA = () => new Promise((resolve, reject) => {
|
|
|
71
52
|
});
|
|
72
53
|
}).on('error', err => {
|
|
73
54
|
_utils.fs.unlink(defaultRootCA); // Delete the file
|
|
74
|
-
|
|
75
|
-
|
|
76
55
|
reject(err);
|
|
77
56
|
});
|
|
78
57
|
});
|
|
79
|
-
|
|
80
58
|
exports.generateRootCA = generateRootCA;
|
|
@@ -4,40 +4,31 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.enableGlobalProxy = exports.disableGlobalProxy = void 0;
|
|
7
|
-
|
|
8
7
|
var _execSync = _interopRequireDefault(require("./execSync"));
|
|
9
|
-
|
|
10
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
9
|
const networkTypes = ['Ethernet', 'Thunderbolt Ethernet', 'Wi-Fi'];
|
|
13
|
-
|
|
14
10
|
const getNetworkType = () => {
|
|
15
11
|
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
16
12
|
for (let i = 0; i < networkTypes.length; i++) {
|
|
17
13
|
const type = networkTypes[i];
|
|
18
14
|
const result = (0, _execSync.default)(`networksetup -getwebproxy ${type}`);
|
|
19
|
-
|
|
20
15
|
if (result.status === 0) {
|
|
21
16
|
return type;
|
|
22
17
|
}
|
|
23
18
|
}
|
|
24
|
-
|
|
25
19
|
throw new Error('Unknown network type');
|
|
26
20
|
};
|
|
27
|
-
|
|
28
21
|
const enableGlobalProxy = (ip, port) => {
|
|
29
|
-
const networkType = getNetworkType();
|
|
22
|
+
const networkType = getNetworkType();
|
|
30
23
|
|
|
24
|
+
// && networksetup -setproxybypassdomains ${networkType} localhost localhost
|
|
31
25
|
(0, _execSync.default)(`networksetup -setwebproxy ${networkType} ${ip} ${port}`);
|
|
32
26
|
(0, _execSync.default)(`networksetup -setsecurewebproxy ${networkType} ${ip} ${port}`);
|
|
33
27
|
};
|
|
34
|
-
|
|
35
28
|
exports.enableGlobalProxy = enableGlobalProxy;
|
|
36
|
-
|
|
37
29
|
const disableGlobalProxy = () => {
|
|
38
30
|
const networkType = getNetworkType();
|
|
39
31
|
(0, _execSync.default)(`networksetup -setwebproxystate ${networkType} off`);
|
|
40
32
|
(0, _execSync.default)(`networksetup -setsecurewebproxystate ${networkType} off`);
|
|
41
33
|
};
|
|
42
|
-
|
|
43
34
|
exports.disableGlobalProxy = disableGlobalProxy;
|
|
@@ -4,42 +4,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
var _execSync = _interopRequireDefault(require("./execSync"));
|
|
13
|
-
|
|
14
10
|
var _macCAManager = require("./macCAManager");
|
|
15
|
-
|
|
16
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
12
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
19
|
-
|
|
20
13
|
const {
|
|
21
14
|
disableGlobalProxy,
|
|
22
15
|
enableGlobalProxy
|
|
23
16
|
} = require("./macProxyManager");
|
|
24
|
-
|
|
25
17
|
class WhistleProxy {
|
|
26
18
|
constructor(config) {
|
|
27
19
|
_defineProperty(this, "rule", void 0);
|
|
28
|
-
|
|
29
20
|
_defineProperty(this, "port", void 0);
|
|
30
|
-
|
|
31
21
|
_defineProperty(this, "bin", void 0);
|
|
32
|
-
|
|
33
22
|
_defineProperty(this, "certDir", void 0);
|
|
34
|
-
|
|
35
23
|
this.rule = config.rule;
|
|
36
|
-
this.port = config.port;
|
|
24
|
+
this.port = config.port;
|
|
25
|
+
// unused
|
|
37
26
|
// this.mode = config.mode; // pureProxy|debug|multiEnv
|
|
38
|
-
|
|
39
27
|
this.bin = _path.default.resolve(_path.default.dirname(require.resolve('whistle')), 'bin/whistle.js');
|
|
40
28
|
this.certDir = _path.default.dirname(_macCAManager.defaultRootCA);
|
|
41
29
|
}
|
|
42
|
-
|
|
43
30
|
async installRootCA() {
|
|
44
31
|
try {
|
|
45
32
|
if (!(0, _macCAManager.isRootCAExists)()) {
|
|
@@ -51,25 +38,18 @@ class WhistleProxy {
|
|
|
51
38
|
throw err;
|
|
52
39
|
}
|
|
53
40
|
}
|
|
54
|
-
|
|
55
41
|
async start() {
|
|
56
42
|
_utils.logger.info(`Starting the proxy server.....`);
|
|
57
|
-
|
|
58
43
|
(0, _execSync.default)(`${this.bin} start --certDir=${this.certDir} --port=${this.port}`);
|
|
59
44
|
(0, _execSync.default)(`${this.bin} use ${this.rule} --force`);
|
|
60
45
|
await this.installRootCA();
|
|
61
46
|
enableGlobalProxy('localhost', this.port);
|
|
62
|
-
|
|
63
47
|
_utils.logger.info(`Proxy Server start on localhost:${this.port}\n`);
|
|
64
48
|
}
|
|
65
|
-
|
|
66
49
|
close() {
|
|
67
50
|
(0, _execSync.default)(`${this.bin} stop`);
|
|
68
51
|
disableGlobalProxy();
|
|
69
|
-
|
|
70
52
|
_utils.logger.info(`Proxy Server has been closed`);
|
|
71
53
|
}
|
|
72
|
-
|
|
73
54
|
}
|
|
74
|
-
|
|
75
55
|
exports.default = WhistleProxy;
|
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "
|
|
14
|
+
"version": "2.0.0-beta.1",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -33,49 +33,26 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@babel/runtime": "^7.18.0",
|
|
35
35
|
"whistle": "^2.7.18",
|
|
36
|
-
"@modern-js/utils": "
|
|
36
|
+
"@modern-js/utils": "2.0.0-beta.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/jest": "^27",
|
|
40
40
|
"@types/node": "^14",
|
|
41
41
|
"typescript": "^4",
|
|
42
42
|
"jest": "^27",
|
|
43
|
-
"@modern-js/core": "
|
|
44
|
-
"@scripts/build": "
|
|
45
|
-
"@scripts/jest-config": "
|
|
43
|
+
"@modern-js/core": "2.0.0-beta.1",
|
|
44
|
+
"@scripts/build": "2.0.0-beta.1",
|
|
45
|
+
"@scripts/jest-config": "2.0.0-beta.1"
|
|
46
46
|
},
|
|
47
47
|
"sideEffects": false,
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"registry": "https://registry.npmjs.org/",
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
|
-
"wireit": {
|
|
53
|
-
"build": {
|
|
54
|
-
"command": "modern build",
|
|
55
|
-
"files": [
|
|
56
|
-
"src/**/*",
|
|
57
|
-
"tsconfig.json",
|
|
58
|
-
"package.json"
|
|
59
|
-
],
|
|
60
|
-
"output": [
|
|
61
|
-
"dist/**/*"
|
|
62
|
-
]
|
|
63
|
-
},
|
|
64
|
-
"test": {
|
|
65
|
-
"command": "jest --passWithNoTests",
|
|
66
|
-
"files": [
|
|
67
|
-
"src/**/*",
|
|
68
|
-
"tsconfig.json",
|
|
69
|
-
"package.json",
|
|
70
|
-
"tests/**/*"
|
|
71
|
-
],
|
|
72
|
-
"output": []
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
52
|
"scripts": {
|
|
76
53
|
"new": "modern new",
|
|
77
54
|
"dev": "modern build --watch",
|
|
78
|
-
"build": "
|
|
79
|
-
"test": "
|
|
55
|
+
"build": "modern build",
|
|
56
|
+
"test": "jest --passWithNoTests"
|
|
80
57
|
}
|
|
81
58
|
}
|