ideas-generator/server/index.js
DJP aec2fe691c Day 1: Complete foundation setup for Ideas Generator 2025
- Created complete project structure (server/, admin/, docs/)
- Initialized Node.js project with all required dependencies
- Configured PostgreSQL database connection
- Implemented basic Express server with security middleware
- Added health check and API placeholder endpoints
- Set up environment configuration with development flags
- Verified all components working and endpoints responding

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-03 09:16:45 -04:00

96 lines
No EOL
2.9 KiB
JavaScript

const express = require('express');
const cors = require('cors');
const helmet = require('helmet');
const morgan = require('morgan');
require('dotenv').config();
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' }));
// 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 placeholder
app.use('/api', (req, res) => {
res.json({
message: 'Ideas Generator 2025 API',
version: '1.0.0',
status: 'Under Development',
endpoints: {
health: '/health',
api: '/api',
chat: '/api/chat (coming soon)',
assistants: '/api/assistants (coming soon)',
conversations: '/api/conversations (coming soon)'
}
});
});
// Basic error handling middleware
app.use((err, req, res, next) => {
console.error('Error:', err.stack);
res.status(500).json({
error: 'Internal Server Error',
message: process.env.NODE_ENV === 'development' ? err.message : 'Something went wrong!'
});
});
// 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, () => {
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(`📊 Environment: ${process.env.NODE_ENV}`);
console.log(`📁 Database: ${process.env.DATABASE_NAME || 'Not configured'}`);
// 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);
});