whistle.mock-plugins 1.1.1 → 1.1.2-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.
@@ -383,7 +383,16 @@ module.exports = function(req, res) {
383
383
 
384
384
  // 处理 PATCH 请求 - 部分更新接口(如启用/禁用状态)
385
385
  if (req.method === 'PATCH') {
386
- const { id, active } = req.query;
386
+ // 支持从路径中获取ID (RESTful风格) 或 从查询参数获取ID
387
+ let id = req.query.id;
388
+
389
+ // 检查路径,支持 /cgi-bin/interfaces/123 形式的请求
390
+ const pathMatch = req.path.match(/\/interfaces\/([^\/]+)$/);
391
+ if (pathMatch && pathMatch[1]) {
392
+ id = pathMatch[1];
393
+ }
394
+
395
+ const { active } = req.query;
387
396
  const patchData = req.body;
388
397
 
389
398
  // 读取接口数据
@@ -466,13 +475,16 @@ module.exports = function(req, res) {
466
475
  });
467
476
  }
468
477
 
478
+ console.log('更新单个接口状态,ID:', id, '数据:', patchData);
479
+
469
480
  // 查找接口
470
481
  const index = interfacesData.interfaces.findIndex(item => item.id === id);
471
482
 
472
483
  if (index === -1) {
484
+ console.error(`接口不存在,ID: ${id},当前共有 ${interfacesData.interfaces.length} 个接口`);
473
485
  return res.status(404).json({
474
486
  code: 404,
475
- message: '接口不存在',
487
+ message: `接口不存在 (ID: ${id})`,
476
488
  data: null
477
489
  });
478
490
  }
@@ -484,6 +496,12 @@ module.exports = function(req, res) {
484
496
  updatedAt: new Date().toISOString()
485
497
  };
486
498
 
499
+ console.log('接口更新成功,接口数据:', {
500
+ id: updatedInterface.id,
501
+ name: updatedInterface.name,
502
+ active: updatedInterface.active
503
+ });
504
+
487
505
  interfacesData.interfaces[index] = updatedInterface;
488
506
  fs.writeJsonSync(interfacesFile, interfacesData, { spaces: 2 });
489
507