feat: Day 21-22 - knowledge base frontend completed, fix CORS and file upload issues
- Complete knowledge base list and detail pages - Complete document upload component - Fix CORS config (add PUT/DELETE method support) - Fix file upload issues (disabled state and beforeUpload return value) - Add detailed debug logs (cleaned up) - Create Day 21-22 completion summary document
This commit is contained in:
@@ -8,6 +8,13 @@ import { agentRoutes } from './routes/agents.js';
|
||||
import { conversationRoutes } from './routes/conversations.js';
|
||||
import knowledgeBaseRoutes from './routes/knowledgeBases.js';
|
||||
|
||||
console.log('\n' + '='.repeat(60));
|
||||
console.log('🔧 正在加载修复后的服务器配置...');
|
||||
console.log('📅 修复版本: 2025-10-11 - CORS完整配置');
|
||||
console.log('='.repeat(60) + '\n');
|
||||
|
||||
console.log('🚨🚨🚨 测试日志: 文件已加载 🚨🚨🚨');
|
||||
|
||||
// 全局处理BigInt序列化
|
||||
(BigInt.prototype as any).toJSON = function() {
|
||||
return Number(this);
|
||||
@@ -27,11 +34,17 @@ const fastify = Fastify({
|
||||
},
|
||||
});
|
||||
|
||||
// 注册CORS插件
|
||||
// 注册CORS插件 - 完整配置
|
||||
await fastify.register(cors, {
|
||||
origin: true, // 开发环境允许所有来源
|
||||
credentials: true,
|
||||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'], // 明确允许的HTTP方法
|
||||
allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With', 'Accept', 'Origin'], // 允许的请求头
|
||||
exposedHeaders: ['Content-Range', 'X-Content-Range'], // 暴露的响应头
|
||||
maxAge: 600, // preflight请求缓存时间(秒)
|
||||
preflightContinue: false, // Fastify处理preflight请求
|
||||
});
|
||||
console.log('✅ CORS已配置: 允许所有HTTP方法 (GET, POST, PUT, DELETE, PATCH, OPTIONS)');
|
||||
|
||||
// 注册文件上传插件
|
||||
await fastify.register(multipart, {
|
||||
@@ -39,6 +52,12 @@ await fastify.register(multipart, {
|
||||
fileSize: 10 * 1024 * 1024, // 10MB
|
||||
},
|
||||
});
|
||||
console.log('✅ 文件上传插件已配置: 最大文件大小 10MB');
|
||||
|
||||
// 添加请求日志钩子(用于调试)
|
||||
fastify.addHook('onRequest', async (request, _reply) => {
|
||||
console.log(`📥 ${request.method} ${request.url} - Origin: ${request.headers.origin || 'none'}`);
|
||||
});
|
||||
|
||||
// 健康检查路由
|
||||
fastify.get('/health', async () => {
|
||||
@@ -116,4 +135,3 @@ const start = async () => {
|
||||
};
|
||||
|
||||
start();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user