@jonathanleelx/meddle 0.5.0-beta.25 → 0.5.0-beta.26
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/bin/index.js +4 -2
- package/bin/lib/output.js +4 -2
- package/dist/core/browser.d.ts +8 -1
- package/dist/core/browser.d.ts.map +1 -1
- package/dist/core/browser.js +239 -36
- package/dist/core/browser.js.map +1 -1
- package/index.js +3 -2
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -59,7 +59,7 @@ if (command === 'mock' || command === 'route' || command === 'session') {
|
|
|
59
59
|
// No command or only flags - start proxy (default behavior)
|
|
60
60
|
require('../index.js')
|
|
61
61
|
} else {
|
|
62
|
-
console.
|
|
62
|
+
console.error(`Unknown command: ${command}`)
|
|
63
63
|
showHelp()
|
|
64
64
|
process.exit(1)
|
|
65
65
|
}
|
|
@@ -106,7 +106,8 @@ Route 命令:
|
|
|
106
106
|
meddle route active 查看当前激活的路由文件
|
|
107
107
|
meddle route active set <file> 设置激活的路由文件
|
|
108
108
|
meddle route create <name> 创建路由文件
|
|
109
|
-
meddle route add <file> <pattern> <target>
|
|
109
|
+
meddle route add <file> <pattern> <target> [--exclusions=]
|
|
110
|
+
添加路由规则;--exclusions= 清空排除项
|
|
110
111
|
meddle route update <file> <pattern> [<target>] [--exclusions=]
|
|
111
112
|
更新路由规则;--exclusions= 清空排除项
|
|
112
113
|
meddle route delete <file> <pattern> 删除路由规则
|
|
@@ -138,6 +139,7 @@ Route 命令:
|
|
|
138
139
|
meddle route preview "https://api.example.com/v1/users" # 预览转发目标
|
|
139
140
|
meddle route preview "https://cdn.com/assets/js/app.js" --file dev-rules --json
|
|
140
141
|
meddle route add dev-rules "api.test.com" "localhost:3000"
|
|
142
|
+
meddle route add dev-rules "api.test.com" "localhost:3000" --exclusions=
|
|
141
143
|
meddle route update dev-rules "api.test.com" --exclusions=
|
|
142
144
|
meddle route active set beta-rules
|
|
143
145
|
|
package/bin/lib/output.js
CHANGED
|
@@ -51,11 +51,13 @@ function success(message) {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
* Print
|
|
54
|
+
* Print a command failure. Human-readable text goes to stderr so stdout stays
|
|
55
|
+
* empty on error. In --json mode this is a no-op; the caller prints the
|
|
56
|
+
* `{ success: false }` object on stdout.
|
|
55
57
|
*/
|
|
56
58
|
function error(message) {
|
|
57
59
|
if (jsonMode) return
|
|
58
|
-
console.
|
|
60
|
+
console.error(chalk.red(' ✗'), message)
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
/**
|
package/dist/core/browser.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import * as os from 'os';
|
|
2
|
+
type Platform = ReturnType<typeof os.platform>;
|
|
3
|
+
/** Name of a browser this machine can launch (`google-chrome`, `Google Chrome`, …), or null. */
|
|
4
|
+
export declare function findInstalledBrowser(platform?: Platform): string | null;
|
|
5
|
+
/** Stop browsers opened by this process. Tests call this from afterAll. */
|
|
6
|
+
export declare function closeLaunchedBrowsers(): void;
|
|
7
|
+
export declare function openBrowserWithProxy(url: string, proxyServer: string, meddleDir: string, remoteDebuggingPort?: number): Promise<boolean>;
|
|
8
|
+
export {};
|
|
2
9
|
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../core/browser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../core/browser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AAmBxB,KAAK,QAAQ,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,CAAA;AAgC9C,gGAAgG;AAChG,wBAAgB,oBAAoB,CAAC,QAAQ,GAAE,QAAwB,GAAG,MAAM,GAAG,IAAI,CAStF;AAwCD,2EAA2E;AAC3E,wBAAgB,qBAAqB,IAAI,IAAI,CAM5C;AA2GD,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,mBAAmB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAuB9I"}
|
package/dist/core/browser.js
CHANGED
|
@@ -36,57 +36,260 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.findInstalledBrowser = findInstalledBrowser;
|
|
40
|
+
exports.closeLaunchedBrowsers = closeLaunchedBrowsers;
|
|
39
41
|
exports.openBrowserWithProxy = openBrowserWithProxy;
|
|
40
42
|
const os = __importStar(require("os"));
|
|
41
43
|
const path = __importStar(require("path"));
|
|
42
44
|
const fs = __importStar(require("fs"));
|
|
43
45
|
const child_process_1 = require("child_process");
|
|
44
46
|
const chalk_1 = __importDefault(require("chalk"));
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
47
|
+
// Linux `execSync('google-chrome …')` waits until Chrome exits. Chrome does not
|
|
48
|
+
// exit, so the caller — including the Vitest worker in tests/browser.spec.ts —
|
|
49
|
+
// blocks forever and the test timeout never fires (#130). Spawn instead. A
|
|
50
|
+
// process that is still alive after a short grace period is open. Exit 0 is
|
|
51
|
+
// also success: Chrome hands the URL to an existing window with the same
|
|
52
|
+
// profile and quits. A non-zero exit is a failed start. Kill anything that
|
|
53
|
+
// fails to start or that tests ask us to close.
|
|
54
|
+
const BROWSER_GRACE_MS = 500;
|
|
55
|
+
const LAUNCHER_TIMEOUT_MS = 2000;
|
|
56
|
+
const launched = [];
|
|
57
|
+
const profiles = [];
|
|
58
|
+
function browserCandidates(platform) {
|
|
59
|
+
if (platform === 'darwin')
|
|
60
|
+
return ['Google Chrome', 'Microsoft Edge', 'Chromium'];
|
|
61
|
+
if (platform === 'win32')
|
|
62
|
+
return ['chrome', 'msedge', 'chromium'];
|
|
63
|
+
return ['google-chrome', 'google-chrome-stable', 'chromium', 'chromium-browser'];
|
|
64
|
+
}
|
|
65
|
+
function commandOnPath(name) {
|
|
66
|
+
const directories = (process.env.PATH || '').split(path.delimiter).filter(Boolean);
|
|
67
|
+
const suffixes = process.platform === 'win32'
|
|
68
|
+
? (process.env.PATHEXT || '.EXE;.CMD;.BAT;.COM').split(';')
|
|
69
|
+
: [''];
|
|
70
|
+
for (const directory of directories) {
|
|
71
|
+
for (const suffix of suffixes) {
|
|
72
|
+
const candidate = path.join(directory, name + suffix);
|
|
73
|
+
try {
|
|
74
|
+
fs.accessSync(candidate, fs.constants.X_OK);
|
|
75
|
+
return candidate;
|
|
67
76
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return true;
|
|
77
|
+
catch {
|
|
78
|
+
// try the next directory
|
|
71
79
|
}
|
|
72
80
|
}
|
|
73
|
-
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
function darwinAppExists(app) {
|
|
85
|
+
const roots = ['/Applications', path.join(os.homedir(), 'Applications')];
|
|
86
|
+
return roots.some((root) => fs.existsSync(path.join(root, `${app}.app`)));
|
|
87
|
+
}
|
|
88
|
+
/** Name of a browser this machine can launch (`google-chrome`, `Google Chrome`, …), or null. */
|
|
89
|
+
function findInstalledBrowser(platform = os.platform()) {
|
|
90
|
+
for (const app of browserCandidates(platform)) {
|
|
91
|
+
if (platform === 'darwin') {
|
|
92
|
+
if (darwinAppExists(app))
|
|
93
|
+
return app;
|
|
74
94
|
continue;
|
|
75
95
|
}
|
|
96
|
+
if (commandOnPath(app))
|
|
97
|
+
return app;
|
|
76
98
|
}
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
function killPid(pid) {
|
|
77
102
|
try {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
(0, child_process_1.execSync)(`start "" "${url}"`, { stdio: 'ignore' });
|
|
82
|
-
else
|
|
83
|
-
(0, child_process_1.execSync)(`xdg-open "${url}"`, { stdio: 'ignore' });
|
|
84
|
-
console.log(chalk_1.default.yellow('未找到 Chrome/Edge,已用默认浏览器打开,请手动设置代理:', proxyServer));
|
|
85
|
-
return true;
|
|
103
|
+
// detached: true puts the child in its own process group, so this also
|
|
104
|
+
// stops Chrome helpers spawned from it.
|
|
105
|
+
process.kill(-pid, 'SIGKILL');
|
|
86
106
|
}
|
|
87
|
-
catch
|
|
88
|
-
|
|
107
|
+
catch {
|
|
108
|
+
try {
|
|
109
|
+
process.kill(pid, 'SIGKILL');
|
|
110
|
+
}
|
|
111
|
+
catch { /* already exited */ }
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function forget(child) {
|
|
115
|
+
const index = launched.indexOf(child);
|
|
116
|
+
if (index >= 0)
|
|
117
|
+
launched.splice(index, 1);
|
|
118
|
+
if (child.pid)
|
|
119
|
+
killPid(child.pid);
|
|
120
|
+
}
|
|
121
|
+
function killProcessesUsingProfile(dir) {
|
|
122
|
+
if (process.platform === 'win32')
|
|
123
|
+
return;
|
|
124
|
+
let output = '';
|
|
125
|
+
try {
|
|
126
|
+
output = (0, child_process_1.execFileSync)('ps', ['-Aww', '-o', 'pid=', '-o', 'args='], {
|
|
127
|
+
encoding: 'utf8',
|
|
128
|
+
timeout: 2000,
|
|
129
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
for (const line of output.split('\n')) {
|
|
136
|
+
if (!line.includes(dir))
|
|
137
|
+
continue;
|
|
138
|
+
const match = /^\s*(\d+)\s/.exec(line);
|
|
139
|
+
if (!match)
|
|
140
|
+
continue;
|
|
141
|
+
const pid = Number(match[1]);
|
|
142
|
+
if (!pid || pid === process.pid)
|
|
143
|
+
continue;
|
|
144
|
+
try {
|
|
145
|
+
process.kill(pid, 'SIGKILL');
|
|
146
|
+
}
|
|
147
|
+
catch { /* already exited */ }
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/** Stop browsers opened by this process. Tests call this from afterAll. */
|
|
151
|
+
function closeLaunchedBrowsers() {
|
|
152
|
+
for (const child of launched.splice(0)) {
|
|
153
|
+
if (!child.pid || child.exitCode !== null || child.signalCode !== null)
|
|
154
|
+
continue;
|
|
155
|
+
killPid(child.pid);
|
|
156
|
+
}
|
|
157
|
+
for (const dir of profiles.splice(0))
|
|
158
|
+
killProcessesUsingProfile(dir);
|
|
159
|
+
}
|
|
160
|
+
function spawnTracked(command, args, shell = false) {
|
|
161
|
+
try {
|
|
162
|
+
const child = (0, child_process_1.spawn)(command, args, {
|
|
163
|
+
detached: true,
|
|
164
|
+
stdio: 'ignore',
|
|
165
|
+
windowsHide: true,
|
|
166
|
+
shell,
|
|
167
|
+
});
|
|
168
|
+
// 'error' is async (ENOENT). A listener is required so Node does not
|
|
169
|
+
// throw it as an unhandled error after we have already moved on.
|
|
170
|
+
child.on('error', () => { });
|
|
171
|
+
launched.push(child);
|
|
172
|
+
return child;
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Browser binaries stay in the foreground. Still running after the grace
|
|
180
|
+
* period means opened. Exit 0 also means opened: a second Chrome with the
|
|
181
|
+
* same profile hands the URL to the existing window and quits.
|
|
182
|
+
*/
|
|
183
|
+
function launchDetached(command, args) {
|
|
184
|
+
return new Promise((resolve) => {
|
|
185
|
+
const child = spawnTracked(command, args);
|
|
186
|
+
if (!child) {
|
|
187
|
+
resolve(false);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
let settled = false;
|
|
191
|
+
let timer;
|
|
192
|
+
const finish = (ok) => {
|
|
193
|
+
if (settled)
|
|
194
|
+
return;
|
|
195
|
+
settled = true;
|
|
196
|
+
if (timer)
|
|
197
|
+
clearTimeout(timer);
|
|
198
|
+
if (ok) {
|
|
199
|
+
// Already exited (handoff). Drop it so a later cleanup cannot
|
|
200
|
+
// signal a recycled pid. A process that is still running stays
|
|
201
|
+
// tracked so tests can close it.
|
|
202
|
+
if (child.exitCode !== null || child.signalCode !== null) {
|
|
203
|
+
const index = launched.indexOf(child);
|
|
204
|
+
if (index >= 0)
|
|
205
|
+
launched.splice(index, 1);
|
|
206
|
+
}
|
|
207
|
+
child.unref();
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
forget(child);
|
|
211
|
+
}
|
|
212
|
+
resolve(ok);
|
|
213
|
+
};
|
|
214
|
+
timer = setTimeout(() => {
|
|
215
|
+
finish(child.exitCode === null && child.signalCode === null);
|
|
216
|
+
}, BROWSER_GRACE_MS);
|
|
217
|
+
child.once('error', () => finish(false));
|
|
218
|
+
child.once('exit', (code) => finish(code === 0));
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
/** `open`, `start`, and `xdg-open` are supposed to exit. Kill them if they do not. */
|
|
222
|
+
function launchExiting(command, args, shell = false) {
|
|
223
|
+
return new Promise((resolve) => {
|
|
224
|
+
const child = spawnTracked(command, args, shell);
|
|
225
|
+
if (!child) {
|
|
226
|
+
resolve(false);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
let settled = false;
|
|
230
|
+
let timer;
|
|
231
|
+
const finish = (ok) => {
|
|
232
|
+
if (settled)
|
|
233
|
+
return;
|
|
234
|
+
settled = true;
|
|
235
|
+
if (timer)
|
|
236
|
+
clearTimeout(timer);
|
|
237
|
+
if (ok) {
|
|
238
|
+
const index = launched.indexOf(child);
|
|
239
|
+
if (index >= 0)
|
|
240
|
+
launched.splice(index, 1);
|
|
241
|
+
child.unref();
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
forget(child);
|
|
245
|
+
}
|
|
246
|
+
resolve(ok);
|
|
247
|
+
};
|
|
248
|
+
timer = setTimeout(() => finish(false), LAUNCHER_TIMEOUT_MS);
|
|
249
|
+
child.once('error', () => finish(false));
|
|
250
|
+
child.once('exit', (code) => finish(code === 0));
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
async function launchCandidate(platform, app, argList, url) {
|
|
254
|
+
if (platform === 'darwin') {
|
|
255
|
+
return launchExiting('open', ['-a', app, '--args', ...argList, url]);
|
|
256
|
+
}
|
|
257
|
+
if (platform === 'win32') {
|
|
258
|
+
return launchExiting('cmd.exe', ['/c', 'start', '', app, ...argList, url]);
|
|
259
|
+
}
|
|
260
|
+
const command = commandOnPath(app);
|
|
261
|
+
if (!command)
|
|
89
262
|
return false;
|
|
263
|
+
return launchDetached(command, [...argList, url]);
|
|
264
|
+
}
|
|
265
|
+
function launchFallback(platform, url) {
|
|
266
|
+
if (platform === 'darwin')
|
|
267
|
+
return launchExiting('open', [url]);
|
|
268
|
+
if (platform === 'win32')
|
|
269
|
+
return launchExiting('cmd.exe', ['/c', 'start', '', url]);
|
|
270
|
+
return launchExiting('xdg-open', [url]);
|
|
271
|
+
}
|
|
272
|
+
async function openBrowserWithProxy(url, proxyServer, meddleDir, remoteDebuggingPort) {
|
|
273
|
+
const platform = os.platform();
|
|
274
|
+
const userDataDir = path.join(meddleDir, 'chrome-proxy');
|
|
275
|
+
fs.mkdirSync(userDataDir, { recursive: true });
|
|
276
|
+
profiles.push(userDataDir);
|
|
277
|
+
const argList = [
|
|
278
|
+
`--user-data-dir=${userDataDir}`,
|
|
279
|
+
`--proxy-server=${proxyServer}`,
|
|
280
|
+
'--window-size=1920,1080',
|
|
281
|
+
];
|
|
282
|
+
if (remoteDebuggingPort)
|
|
283
|
+
argList.push(`--remote-debugging-port=${remoteDebuggingPort}`);
|
|
284
|
+
for (const app of browserCandidates(platform)) {
|
|
285
|
+
if (await launchCandidate(platform, app, argList, url))
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
if (await launchFallback(platform, url)) {
|
|
289
|
+
console.log(chalk_1.default.yellow('未找到 Chrome/Edge,已用默认浏览器打开,请手动设置代理:', proxyServer));
|
|
290
|
+
return true;
|
|
90
291
|
}
|
|
292
|
+
console.error(chalk_1.default.red('浏览器并未启动:'), 'no supported browser found');
|
|
293
|
+
return false;
|
|
91
294
|
}
|
|
92
295
|
//# sourceMappingURL=browser.js.map
|
package/dist/core/browser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../core/browser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../core/browser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,oDASC;AAyCD,sDAMC;AA2GD,oDAuBC;AA9OD,uCAAwB;AACxB,2CAA4B;AAC5B,uCAAwB;AACxB,iDAAsE;AACtE,kDAAyB;AAEzB,gFAAgF;AAChF,+EAA+E;AAC/E,2EAA2E;AAC3E,4EAA4E;AAC5E,yEAAyE;AACzE,2EAA2E;AAC3E,gDAAgD;AAChD,MAAM,gBAAgB,GAAG,GAAG,CAAA;AAC5B,MAAM,mBAAmB,GAAG,IAAI,CAAA;AAEhC,MAAM,QAAQ,GAAmB,EAAE,CAAA;AACnC,MAAM,QAAQ,GAAa,EAAE,CAAA;AAI7B,SAAS,iBAAiB,CAAC,QAAkB;IACzC,IAAI,QAAQ,KAAK,QAAQ;QAAE,OAAO,CAAC,eAAe,EAAE,gBAAgB,EAAE,UAAU,CAAC,CAAA;IACjF,IAAI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AED,IAAI,MAAM,cAAc,CAAC,QAAQ,EAAE,GAAG,CAAC,EAAE,CAAC;QACtC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,oCAAoC,EAAE,WAAW,CAAC,CAAC,CAAA;QAC5E,OAAO,IAAI,CAAA;IACf,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,4BAA4B,CAAC,CAAA;IAClE,OAAO,KAAK,CAAA;AAChB,CAAC"}
|
package/index.js
CHANGED
|
@@ -549,7 +549,7 @@ localWSServer.on('connection', (client, req) => {})
|
|
|
549
549
|
await ensureRootCA({ trustCheckAsync: true })
|
|
550
550
|
await pluginBoot.bootstrapBuiltinPlugins()
|
|
551
551
|
const port = await getFreePort()
|
|
552
|
-
proxyServer.listen(port, remoteAccess.bindHost, () => {
|
|
552
|
+
proxyServer.listen(port, remoteAccess.bindHost, async () => {
|
|
553
553
|
const proxyUrl = `http://127.0.0.1:${port}`
|
|
554
554
|
console.log(chalk.green('代理服务器已启动:'), chalk.cyan(proxyUrl))
|
|
555
555
|
proxyDebug('proxy-server start on ' + chalk.green(proxyUrl))
|
|
@@ -568,7 +568,8 @@ localWSServer.on('connection', (client, req) => {})
|
|
|
568
568
|
if (ctx.AUTO_OPEN) {
|
|
569
569
|
const proxyAddr = `127.0.0.1:${port}`
|
|
570
570
|
const remotePort = process.env.MEDDLE_OPEN_CHROMEDEVTOOLS ? 9222 : undefined
|
|
571
|
-
|
|
571
|
+
const opened = await openBrowserWithProxy(proxyUrl, proxyAddr, ctx.meddleDir, remotePort).catch(() => false)
|
|
572
|
+
if (opened) {
|
|
572
573
|
console.log(chalk.green('已启动浏览器(代理:'), proxyAddr + chalk.green(')'))
|
|
573
574
|
} else {
|
|
574
575
|
console.log(chalk.yellow('浏览器并未启动,请手动打开'), chalk.cyan(proxyUrl), chalk.yellow('并设置代理'), proxyAddr)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jonathanleelx/meddle",
|
|
3
|
-
"version": "0.5.0-beta.
|
|
3
|
+
"version": "0.5.0-beta.26",
|
|
4
4
|
"description": "A simple development proxy server with custom routing rules, mock responses, HTTPS interception, and a plugin system",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "index.js",
|