whistle.mock-plugins 1.1.3-beta.2 → 1.1.3-beta.3

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,7 +38,25 @@ 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
+ // 原始URL路径
42
+ let urlPath = req.url.replace(/\?.*$/, '');
43
+ let controller = CGI_MODULES[APP_ROOT + urlPath];
44
+
45
+ // 如果直接匹配失败,尝试匹配带路径参数的路由
46
+ if (!controller) {
47
+ // 检查是否是接口相关的路由(带ID参数)
48
+ const interfacesMatch = urlPath.match(/^\/cgi-bin\/interfaces(\/[^\/]+)?$/);
49
+ if (interfacesMatch) {
50
+ controller = CGI_MODULES[APP_ROOT + '/cgi-bin/interfaces'];
51
+ // 将路径参数添加到请求对象中
52
+ if (interfacesMatch[1]) {
53
+ const id = interfacesMatch[1].substring(1); // 移除前面的'/'
54
+ req.params = req.params || {};
55
+ req.params.id = id;
56
+ }
57
+ }
58
+ }
59
+
42
60
  if (!controller) {
43
61
  res.status(404).end('Not found');
44
62
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whistle.mock-plugins",
3
- "version": "1.1.3-beta.2",
3
+ "version": "1.1.3-beta.3",
4
4
  "description": "Whistle 插件,用于快速创建 API 模拟数据",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {