@jonathanleelx/meddle 0.0.3 → 0.1.2

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.
@@ -0,0 +1,40 @@
1
+ /**
2
+ * meddle version - Print version information
3
+ */
4
+
5
+ const os = require('os')
6
+ const path = require('path')
7
+ const output = require('../lib/output')
8
+
9
+ const args = process.argv.slice(2)
10
+ const jsonFlag = args.includes('--json')
11
+ output.setJsonMode(jsonFlag)
12
+
13
+ function getVersionInfo() {
14
+ const pkg = require(path.join(__dirname, '../../package.json'))
15
+ return {
16
+ name: pkg.name,
17
+ version: pkg.version,
18
+ node: process.version,
19
+ platform: `${os.platform()} ${os.arch()}`,
20
+ homepage: pkg.homepage,
21
+ }
22
+ }
23
+
24
+ function run() {
25
+ const info = getVersionInfo()
26
+
27
+ if (output.isJsonMode()) {
28
+ output.jsonRaw(info)
29
+ return
30
+ }
31
+
32
+ output.header('Meddle Version')
33
+ output.kv('Package', info.name)
34
+ output.kv('Version', info.version)
35
+ output.kv('Node.js', info.node)
36
+ output.kv('Platform', info.platform)
37
+ output.kv('Homepage', info.homepage)
38
+ }
39
+
40
+ run()
package/bin/index.js CHANGED
@@ -31,6 +31,7 @@ const commands = {
31
31
  'supervise': './commands/supervise.js',
32
32
  'url': './commands/url.js',
33
33
  'status': './commands/status.js',
34
+ 'version': './commands/version.js',
34
35
  'session': './commands/session/index.js',
35
36
  'mock': './commands/mock/index.js',
36
37
  'route': './commands/route/index.js'
@@ -68,6 +69,7 @@ Meddle - 开发代理工具
68
69
  meddle doctor 检查配置文件健康状况
69
70
  meddle url 获取代理 URL
70
71
  meddle status 查看代理状态
72
+ meddle version 查看版本信息
71
73
 
72
74
  Session 命令 (多实例隔离,预览功能):
73
75
  meddle session create [--name <label>] [--port <port>]
@@ -0,0 +1,2 @@
1
+ export declare function isStreamingResponse(headers?: Record<string, unknown>): boolean;
2
+ //# sourceMappingURL=streaming-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streaming-response.d.ts","sourceRoot":"","sources":["../../core/streaming-response.ts"],"names":[],"mappings":"AAQA,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,OAAO,CAMlF"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isStreamingResponse = isStreamingResponse;
4
+ const STREAMING_CONTENT_TYPES = [
5
+ 'text/event-stream',
6
+ 'application/x-ndjson',
7
+ 'application/ndjson',
8
+ 'application/json-seq',
9
+ 'application/stream+json',
10
+ ];
11
+ function isStreamingResponse(headers = {}) {
12
+ const contentType = Object.entries(headers).find(([key]) => key.toLowerCase() === 'content-type')?.[1];
13
+ if (typeof contentType !== 'string')
14
+ return false;
15
+ const mediaType = contentType.split(';', 1)[0].trim().toLowerCase();
16
+ return STREAMING_CONTENT_TYPES.includes(mediaType);
17
+ }
18
+ //# sourceMappingURL=streaming-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streaming-response.js","sourceRoot":"","sources":["../../core/streaming-response.ts"],"names":[],"mappings":";;AAQA,kDAMC;AAdD,MAAM,uBAAuB,GAAG;IAC5B,mBAAmB;IACnB,sBAAsB;IACtB,oBAAoB;IACpB,sBAAsB;IACtB,yBAAyB;CAC5B,CAAA;AAED,SAAgB,mBAAmB,CAAC,UAAmC,EAAE;IACrE,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IACtG,IAAI,OAAO,WAAW,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAEjD,MAAM,SAAS,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IACnE,OAAO,uBAAuB,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;AACtD,CAAC"}
package/index.js CHANGED
@@ -106,6 +106,7 @@ const { createMockHandler } = require('./dist/core/mock-handler')
106
106
  const { handleMapLocalRequest } = require('./dist/core/map-local')
107
107
  const { createRouteLoader } = require('./dist/core/route-loader')
108
108
  const { createPluginIntercept } = require('./dist/core/plugin-intercept')
109
+ const { isStreamingResponse } = require('./dist/core/streaming-response')
109
110
  const { createPluginBootstrapRunner } = require('./dist/core/plugin-bootstrap-runner')
110
111
  const { openBrowserWithProxy } = require('./dist/core/browser')
111
112
  const { handleLocalRequest } = require('./dist/core/static-server')
@@ -382,10 +383,11 @@ const proxyServer = http.createServer(async (req, res) => {
382
383
  const url = new URL(target.startsWith('http') ? target : req.url, 'http://' + req.headers.host)
383
384
  const routeChanged = source !== url.href
384
385
  const startTime = Date.now()
385
- const intercepting = pluginIntercept.shouldInterceptResponse()
386
-
387
386
  const proxyReq = http.request(url, { method: req.method, headers: stripProxyHeaders(req.headers) }, (proxyRes) => {
388
387
  const resChunks = []
388
+ const pluginResponseInterception = pluginIntercept.shouldInterceptResponse()
389
+ const streamingResponse = isStreamingResponse(proxyRes.headers)
390
+ const intercepting = pluginResponseInterception && !streamingResponse
389
391
  let proxyResponseSettled = false
390
392
  const handleProxyResponseError = (err) => {
391
393
  if (proxyResponseSettled) return
@@ -426,7 +428,7 @@ const proxyServer = http.createServer(async (req, res) => {
426
428
  duration: Date.now() - startTime,
427
429
  ...clientIdentity,
428
430
  }
429
- if (!intercepting) pluginIntercept.emitLegacyResponseToPlugins(logData)
431
+ if (!pluginResponseInterception) pluginIntercept.emitLegacyResponseToPlugins(logData)
430
432
  const responseEncoding = proxyRes.headers && proxyRes.headers['content-encoding']
431
433
  // 获取 inspection 信息
432
434
  const inspectionStages = routeDecision.meta?._inspectionStages || []
@@ -489,6 +491,7 @@ localWSServer.on('connection', (client, req) => {})
489
491
  const port = await getFreePort()
490
492
  proxyServer.listen(port, remoteAccess.bindHost, () => {
491
493
  const proxyUrl = `http://127.0.0.1:${port}`
494
+ console.log(chalk.green('代理服务器已启动:'), chalk.cyan(proxyUrl))
492
495
  proxyDebug('proxy-server start on ' + chalk.green(proxyUrl))
493
496
  proxyDebug('plugin pipeline mode: ' + chalk.cyan(ctx.requestPipeline.mode))
494
497
  if (ctx.requestPipeline.mode === 'on') {
@@ -624,10 +627,12 @@ proxyServer.on('connect', async (req, socket, head) => {
624
627
 
625
628
  const routeChanged = source !== target
626
629
  const startTime = Date.now()
627
- const intercepting = pluginIntercept.shouldInterceptResponse()
628
630
  try {
629
631
  const proxyRes = await makeProxyRequest(target, req.method, stripProxyHeaders(req.headers), reqBody)
630
632
  const resChunks = []
633
+ const pluginResponseInterception = pluginIntercept.shouldInterceptResponse()
634
+ const streamingResponse = isStreamingResponse(proxyRes.headers)
635
+ const intercepting = pluginResponseInterception && !streamingResponse
631
636
  let proxyResponseSettled = false
632
637
  const handleProxyResponseError = (err) => {
633
638
  if (proxyResponseSettled) return
@@ -669,7 +674,7 @@ proxyServer.on('connect', async (req, socket, head) => {
669
674
  statusCode: proxyRes.statusCode, duration: Date.now() - startTime,
670
675
  ...requestClientIdentity,
671
676
  }
672
- if (!intercepting) pluginIntercept.emitLegacyResponseToPlugins(logData)
677
+ if (!pluginResponseInterception) pluginIntercept.emitLegacyResponseToPlugins(logData)
673
678
  const responseEncoding = proxyRes.headers && proxyRes.headers['content-encoding']
674
679
  // 获取 inspection 信息
675
680
  const inspectionStages = routeDecision.meta?._inspectionStages || []
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jonathanleelx/meddle",
3
- "version": "0.0.3",
3
+ "version": "0.1.2",
4
4
  "description": "A simple development proxy server with custom routing rules, mock responses, HTTPS interception, and a plugin system",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -53,6 +53,7 @@
53
53
  "plugin"
54
54
  ],
55
55
  "author": "JonathanLee-LX",
56
+ "packageManager": "pnpm@10.34.5",
56
57
  "license": "MIT",
57
58
  "repository": {
58
59
  "type": "git",