whistle.mock-plugins 1.1.2-dev.1 → 1.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.
package/lib/ui-server.js CHANGED
@@ -38,8 +38,21 @@ app.all('/cgi-bin/*', function(req, res) {
38
38
  res.setHeader('Access-Control-Allow-Credentials', true);
39
39
  }
40
40
 
41
- const controller = CGI_MODULES[APP_ROOT + req.url.replace(/\?.*$/, '')];
41
+ // 支持RESTful API路径
42
+ // 例如 /cgi-bin/interfaces/123 应该映射到 /cgi-bin/interfaces 控制器
43
+ let controllerPath = req.url.replace(/\?.*$/, '');
44
+
45
+ // 处理RESTful路径,如 /cgi-bin/interfaces/123 => /cgi-bin/interfaces
46
+ const restMatch = controllerPath.match(/^(\/cgi-bin\/[^\/]+)\/[^\/]+$/);
47
+ if (restMatch) {
48
+ controllerPath = restMatch[1];
49
+ }
50
+
51
+ // 尝试加载控制器
52
+ const controller = CGI_MODULES[APP_ROOT + controllerPath];
53
+
42
54
  if (!controller) {
55
+ console.error(`未找到CGI控制器: ${controllerPath},原始URL: ${req.url}`);
43
56
  res.status(404).end('Not found');
44
57
  return;
45
58
  }
@@ -48,6 +61,7 @@ app.all('/cgi-bin/*', function(req, res) {
48
61
  // 提供数据目录给CGI处理程序
49
62
  controller.call({ dataDir: DATA_DIR }, req, res);
50
63
  } catch(e) {
64
+ console.error('CGI处理错误:', e);
51
65
  res.status(500).end(e.stack);
52
66
  }
53
67
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whistle.mock-plugins",
3
- "version": "1.1.2-dev.1",
3
+ "version": "1.1.2",
4
4
  "description": "Whistle 插件,用于快速创建 API 模拟数据",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {