Major Features Implemented: - Full Vue.js 3 admin interface with Vite build system - OpenAI Chat Completions API integration (replaced deprecated Assistants API) - PostgreSQL database with Sequelize ORM - Complete conversation management system - User authentication system (admin@oliver.agency, user@oliver.agency) - AI-powered conversation title generation - Server-Sent Events for streaming responses - Conversation soft delete functionality - Rate limiting middleware with development bypass Backend Infrastructure: - Node.js/Express server with comprehensive error handling - Database models: User, Assistant, Conversation, Message - Chat API endpoints with full conversation history context - Conversation CRUD operations with soft delete - Migration and seeding scripts - Environment-based configuration Frontend Features: - Responsive Vue.js interface with router - Real-time chat with streaming responses - Conversation sidebar with delete functionality - Agent selection dropdown - Persistent user sessions with hash-based user IDs - Conversation history loading and continuity - Login system with user role management - Prominent logout functionality Technical Improvements: - Fixed conversation continuity by loading full message history - Implemented conversation title generation using GPT-4o-mini - Added conversation persistence mechanisms (periodic refresh, window focus) - Enhanced error handling and rate limiting - Proper environment variable management - Clean project structure with separated concerns 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
108 lines
No EOL
3.3 KiB
JavaScript
108 lines
No EOL
3.3 KiB
JavaScript
const express = require('express');
|
|
const cors = require('cors');
|
|
const helmet = require('helmet');
|
|
const morgan = require('morgan');
|
|
require('dotenv').config();
|
|
|
|
const { testConnection } = require('./config/database');
|
|
const { generalLimiter } = require('./middleware/rateLimiter');
|
|
const errorHandler = require('./middleware/errorHandler');
|
|
const chatRouter = require('./routes/chat');
|
|
const assistantsRouter = require('./routes/assistants');
|
|
|
|
const app = express();
|
|
const PORT = process.env.PORT || 3000;
|
|
|
|
// Security middleware
|
|
app.use(helmet());
|
|
|
|
// CORS middleware - permissive for development
|
|
app.use(cors({
|
|
origin: process.env.NODE_ENV === 'development' ? true : ['http://localhost:8080', 'https://ai-sandbox.oliver.solutions'],
|
|
credentials: true
|
|
}));
|
|
|
|
// Request logging
|
|
app.use(morgan('combined'));
|
|
|
|
// Body parsing middleware
|
|
app.use(express.json({ limit: '10mb' }));
|
|
app.use(express.urlencoded({ extended: true, limit: '10mb' }));
|
|
|
|
// Rate limiting
|
|
app.use(generalLimiter);
|
|
|
|
// Health check endpoint
|
|
app.get('/health', (req, res) => {
|
|
res.json({
|
|
status: 'ok',
|
|
timestamp: new Date().toISOString(),
|
|
environment: process.env.NODE_ENV,
|
|
version: '1.0.0',
|
|
service: 'Ideas Generator 2025 Backend'
|
|
});
|
|
});
|
|
|
|
// API routes
|
|
app.use('/api/chat', chatRouter);
|
|
app.use('/api/assistants', assistantsRouter);
|
|
|
|
// API info endpoint
|
|
app.get('/api', (req, res) => {
|
|
res.json({
|
|
message: 'Ideas Generator 2025 API',
|
|
version: '1.0.0',
|
|
status: 'Active',
|
|
endpoints: {
|
|
health: '/health',
|
|
api: '/api',
|
|
chat: '/api/chat/completions',
|
|
assistants: '/api/assistants',
|
|
conversations: '/api/chat/conversations/:id/messages'
|
|
}
|
|
});
|
|
});
|
|
|
|
// Error handling middleware
|
|
app.use(errorHandler);
|
|
|
|
// 404 handler
|
|
app.use((req, res) => {
|
|
res.status(404).json({
|
|
error: 'Not Found',
|
|
message: `Route ${req.originalUrl} not found`,
|
|
availableRoutes: ['/health', '/api']
|
|
});
|
|
});
|
|
|
|
// Start server
|
|
app.listen(PORT, async () => {
|
|
console.log(`🚀 Ideas Gen 2025 Server running on port ${PORT}`);
|
|
console.log(`🏥 Health check: http://localhost:${PORT}/health`);
|
|
console.log(`🔧 API endpoint: http://localhost:${PORT}/api`);
|
|
console.log(`💬 Chat endpoint: http://localhost:${PORT}/api/chat/completions`);
|
|
console.log(`🤖 Assistants endpoint: http://localhost:${PORT}/api/assistants`);
|
|
console.log(`📊 Environment: ${process.env.NODE_ENV}`);
|
|
console.log(`📁 Database: ${process.env.DATABASE_NAME || 'Not configured'}`);
|
|
|
|
// Test database connection
|
|
await testConnection();
|
|
|
|
// Log important environment status
|
|
if (!process.env.OPENAI_API_KEY || process.env.OPENAI_API_KEY.includes('your-actual')) {
|
|
console.warn('⚠️ WARNING: OpenAI API key not configured! Update .env file.');
|
|
} else {
|
|
console.log('✅ OpenAI API key configured');
|
|
}
|
|
});
|
|
|
|
// Graceful shutdown
|
|
process.on('SIGINT', () => {
|
|
console.log('\n🛑 Received SIGINT. Graceful shutdown...');
|
|
process.exit(0);
|
|
});
|
|
|
|
process.on('SIGTERM', () => {
|
|
console.log('\n🛑 Received SIGTERM. Graceful shutdown...');
|
|
process.exit(0);
|
|
}); |