whistle.mock-plugins 1.0.6-beta.9 → 1.1.0

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.
@@ -75,6 +75,17 @@ module.exports = function(req, res) {
75
75
 
76
76
  const filteredInterfaces = interfacesData.interfaces.filter(item => item.featureId === featureId);
77
77
 
78
+ console.log('GET获取接口列表:', {
79
+ featureId,
80
+ totalCount: filteredInterfaces.length,
81
+ interfacesWithResponses: filteredInterfaces.map(item => ({
82
+ name: item.name,
83
+ hasResponses: !!item.responses,
84
+ responsesCount: item.responses ? item.responses.length : 0,
85
+ activeResponseId: item.activeResponseId
86
+ }))
87
+ });
88
+
78
89
  return res.json({
79
90
  code: 0,
80
91
  message: '成功',
@@ -175,6 +186,8 @@ module.exports = function(req, res) {
175
186
  urlPattern: interfaceData.urlPattern,
176
187
  proxyType: interfaceData.proxyType,
177
188
  responseContent: interfaceData.responseContent,
189
+ responses: interfaceData.responses || interfacesData.interfaces[index].responses || [],
190
+ activeResponseId: interfaceData.activeResponseId !== undefined ? interfaceData.activeResponseId : interfacesData.interfaces[index].activeResponseId,
178
191
  targetUrl: interfaceData.targetUrl,
179
192
  customHeaders: interfaceData.customHeaders || {},
180
193
  filePath: interfaceData.filePath,
@@ -184,6 +197,12 @@ module.exports = function(req, res) {
184
197
  active: interfaceData.active !== false
185
198
  };
186
199
 
200
+ console.log('更新接口,包含多响应数据:', {
201
+ name: interfacesData.interfaces[index].name,
202
+ responsesCount: interfacesData.interfaces[index].responses.length,
203
+ activeResponseId: interfacesData.interfaces[index].activeResponseId
204
+ });
205
+
187
206
  fs.writeJsonSync(interfacesFile, interfacesData, { spaces: 2 });
188
207
 
189
208
  return res.json({
@@ -200,6 +219,8 @@ module.exports = function(req, res) {
200
219
  urlPattern: interfaceData.urlPattern,
201
220
  proxyType: interfaceData.proxyType || 'response',
202
221
  responseContent: interfaceData.responseContent || '',
222
+ responses: interfaceData.responses || [],
223
+ activeResponseId: interfaceData.activeResponseId || null,
203
224
  targetUrl: interfaceData.targetUrl || '',
204
225
  customHeaders: interfaceData.customHeaders || {},
205
226
  filePath: interfaceData.filePath || '',
@@ -210,6 +231,12 @@ module.exports = function(req, res) {
210
231
  contentType: interfaceData.contentType || 'text/plain'
211
232
  };
212
233
 
234
+ console.log('创建新接口,包含多响应数据:', {
235
+ name: newInterface.name,
236
+ responsesCount: newInterface.responses.length,
237
+ activeResponseId: newInterface.activeResponseId
238
+ });
239
+
213
240
  // 确保interfaces数组存在
214
241
  if (!Array.isArray(interfacesData.interfaces)) {
215
242
  interfacesData.interfaces = [];
@@ -317,6 +344,8 @@ module.exports = function(req, res) {
317
344
  urlPattern: interfaceData.urlPattern || interfacesData.interfaces[index].urlPattern,
318
345
  proxyType: interfaceData.proxyType || interfacesData.interfaces[index].proxyType,
319
346
  responseContent: interfaceData.responseContent !== undefined ? interfaceData.responseContent : interfacesData.interfaces[index].responseContent,
347
+ responses: interfaceData.responses !== undefined ? interfaceData.responses : (interfacesData.interfaces[index].responses || []),
348
+ activeResponseId: interfaceData.activeResponseId !== undefined ? interfaceData.activeResponseId : interfacesData.interfaces[index].activeResponseId,
320
349
  targetUrl: interfaceData.targetUrl !== undefined ? interfaceData.targetUrl : interfacesData.interfaces[index].targetUrl,
321
350
  customHeaders: interfaceData.customHeaders !== undefined ? interfaceData.customHeaders : interfacesData.interfaces[index].customHeaders || {},
322
351
  filePath: interfaceData.filePath !== undefined ? interfaceData.filePath : interfacesData.interfaces[index].filePath,
@@ -328,6 +357,12 @@ module.exports = function(req, res) {
328
357
  updatedAt: new Date().toISOString()
329
358
  };
330
359
 
360
+ console.log('PUT更新接口,包含多响应数据:', {
361
+ name: updatedInterface.name,
362
+ responsesCount: updatedInterface.responses.length,
363
+ activeResponseId: updatedInterface.activeResponseId
364
+ });
365
+
331
366
  interfacesData.interfaces[index] = updatedInterface;
332
367
  fs.writeJsonSync(interfacesFile, interfacesData, { spaces: 2 });
333
368
 
@@ -44,7 +44,7 @@ const regexCache = new Map();
44
44
  // URL匹配函数,提取为纯函数减少重复代码
45
45
  const isUrlMatchPattern = (url, pattern, proxyType) => {
46
46
  if (!url || !pattern) return false;
47
-
47
+ console.log(`isUrlMatchPattern ${url} - ${pattern}`);
48
48
  try {
49
49
  // 对于url_redirect类型,需要完全匹配
50
50
  if (proxyType === 'url_redirect') {
@@ -241,14 +241,9 @@ module.exports = async function(req, res) {
241
241
  // 使用URL匹配检查
242
242
  const isMatch = isUrlMatchPattern(url, pattern, proxyType);
243
243
 
244
- // 如果存在method配置,检查HTTP方法是否匹配
245
- const methodMatch = !targetInterface.method ||
246
- targetInterface.method === 'all' ||
247
- targetInterface.method.toLowerCase() === 'all' ||
248
- req.method.toLowerCase() === targetInterface.method.toLowerCase();
249
-
250
- // 确定匹配结果
251
- const matchResult = isMatch && methodMatch;
244
+ // 测试接口只验证URL模式匹配,不验证HTTP方法
245
+ // 因为这里的req.method是测试请求的POST方法,与接口配置的HTTP方法无关
246
+ const matchResult = isMatch;
252
247
 
253
248
  // 构建测试结果
254
249
  const result = {
@@ -260,7 +255,7 @@ module.exports = async function(req, res) {
260
255
  isMatch: matchResult,
261
256
  matchDetail: {
262
257
  urlMatch: isMatch,
263
- methodMatch: methodMatch
258
+ note: 'HTTP方法匹配在测试模式下不进行验证,仅验证URL模式匹配'
264
259
  }
265
260
  };
266
261