Files
Agent-n8n/web_frontend/web_result/server.js
Yep_Q 83dc9270c8 fix: 修复WorkflowPageV3组件TypeScript错误和清理副本文件
详细说明:
- 修复WorkflowPageV3.tsx中的TypeScript类型错误
- 移除未使用的executionTimeoutRef变量
- 修复style标签的jsx属性问题
- 将deprecated的substr()改为substring()
- 清理n8n目录下的副本文件
- 添加server.js和start脚本用于静态文件服务

影响的文件:
- web_frontend/exhibition-demo/src/pages/WorkflowPageV3.tsx
- web_frontend/exhibition-demo/src/components/ResultModal.tsx
- web_frontend/web_result/server.js (新增)
- web_frontend/web_result/start.bat (新增)
- web_frontend/web_result/start.sh (新增)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-08 16:34:51 +08:00

99 lines
2.4 KiB
JavaScript

const http = require('http');
const fs = require('fs');
const path = require('path');
const url = require('url');
const PORT = 4155;
const HOST = '0.0.0.0';
// MIME 类型映射
const mimeTypes = {
'.html': 'text/html; charset=utf-8',
'.css': 'text/css',
'.js': 'text/javascript',
'.json': 'application/json',
'.png': 'image/png',
'.jpg': 'image/jpeg',
'.jpeg': 'image/jpeg',
'.gif': 'image/gif',
'.svg': 'image/svg+xml',
'.ico': 'image/x-icon',
'.woff': 'font/woff',
'.woff2': 'font/woff2',
'.ttf': 'font/ttf',
'.eot': 'font/eot'
};
// 创建服务器
const server = http.createServer((req, res) => {
// 解析 URL
const parsedUrl = url.parse(req.url);
let pathname = decodeURIComponent(parsedUrl.pathname);
// 默认文件
if (pathname === '/') {
pathname = '/index.html';
}
// 构建文件路径
const filePath = path.join(__dirname, pathname);
// 安全检查:确保文件路径在当前目录内
if (!filePath.startsWith(__dirname)) {
res.writeHead(403);
res.end('Forbidden');
return;
}
// 检查文件是否存在
fs.stat(filePath, (err, stats) => {
if (err) {
// 文件不存在
res.writeHead(404);
res.end('Not Found');
return;
}
if (stats.isDirectory()) {
// 如果是目录,尝试加载 index.html
const indexPath = path.join(filePath, 'index.html');
fs.stat(indexPath, (err, stats) => {
if (err) {
res.writeHead(404);
res.end('Not Found');
return;
}
serveFile(indexPath, res);
});
} else {
// 提供文件
serveFile(filePath, res);
}
});
});
// 提供文件的函数
function serveFile(filePath, res) {
const ext = path.extname(filePath);
const contentType = mimeTypes[ext] || 'application/octet-stream';
fs.readFile(filePath, (err, content) => {
if (err) {
res.writeHead(500);
res.end('Internal Server Error');
return;
}
res.writeHead(200, { 'Content-Type': contentType });
res.end(content);
});
}
// 启动服务器
server.listen(PORT, HOST, () => {
console.log('======================================');
console.log(' Web Result 静态服务器');
console.log(` 运行地址: http://localhost:${PORT}`);
console.log(' 按 Ctrl+C 停止服务器');
console.log('======================================');
});