whistle.mock-plugins 1.1.2-beta.1 → 1.1.2-dev.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/app/cgi-bin/interfaces.js +22 -3
- package/app/public/js/index.js +1 -1
- package/lib/ui-server.js +15 -1
- package/package.json +1 -1
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
|
-
|
|
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
|
});
|