AeThex-Connect/src/backend/server.js
MrPiglr 185e76c0c4
Phase 3: GameForge Integration - Auto-Provisioning & Role-Based Channels
🏗️ Database Schema
- Create gameforge_integrations table
- Add gameforge_project_id to conversations
- Create audit_logs table for operation tracking
- Add metadata and is_archived columns
- Implement indexes and triggers

🔧 Backend Services
- GameForgeIntegrationService (450+ lines)
  - Auto-provision projects and channels
  - Team member synchronization
  - Role-based permission enforcement
  - System notification delivery
  - Project archival management

🔐 Authentication & Security
- GameForge API key authentication
- HMAC-SHA256 signature validation
- Timestamp verification (5-minute window)
- Replay attack prevention
- Audit logging

🌐 API Endpoints (8 endpoints)
- POST /api/gameforge/projects - Provision project
- PATCH /api/gameforge/projects/:id/team - Update team
- DELETE /api/gameforge/projects/:id - Archive project
- GET /api/gameforge/projects/:id/channels - List channels
- POST /api/gameforge/projects/:id/channels - Create channel
- PATCH /api/gameforge/channels/:id - Update channel
- DELETE /api/gameforge/channels/:id - Delete channel
- POST /api/gameforge/projects/:id/notify - Send notification

🎨 Frontend Components
- GameForgeChat - Embedded chat container
- ChannelList - Channel navigation with icons
- ChannelView - Message display and input
- Responsive CSS with mobile support

📚 Documentation
- PHASE3-GAMEFORGE.md - Complete technical docs
- GAMEFORGE-EXAMPLES.md - Integration code samples
- API reference with request/response examples
- Testing guidelines and checklist

 Features
- Automatic channel provisioning on project creation
- Role-based channel permissions (dev, art, testing, etc.)
- System notifications (builds, commits, deployments)
- Team member sync with role updates
- Custom channel creation
- Project archival

📊 Stats
- 16 new files created
- 2 files updated
- ~2,750 lines of code
- 8 API endpoints
- 7 React components
2026-01-10 04:57:23 +00:00

98 lines
3 KiB
JavaScript

const express = require('express');
const http = require('http');
const cors = require('cors');
const helmet = require('helmet');
const rateLimit = require('express-rate-limit');
require('dotenv').config();
const domainRoutes = require('./routes/domainRoutes');
const messagingRoutes = require('./routes/messagingRoutes');
const gameforgeRoutes = require('./routes/gameforgeRoutes');
const socketService = require('./services/socketService');
const app = express();
const httpServer = http.createServer(app);
const PORT = process.env.PORT || 3000;
// Trust proxy for Codespaces/containers
app.set('trust proxy', 1);
// Security middleware
app.use(helmet());
app.use(cors({
origin: process.env.FRONTEND_URL || 'http://localhost:5173',
credentials: true
}));
// Rate limiting
const limiter = rateLimit({
windowMs: parseInt(process.env.RATE_LIMIT_WINDOW_MS) || 15 * 60 * 1000, // 15 minutes
max: parseInt(process.env.RATE_LIMIT_MAX_REQUESTS) || 100,
message: 'Too many requests from this IP, please try again later.',
standardHeaders: true,
legacyHeaders: false,
});
app.use('/api/', limiter);
// Body parsing middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Health check endpoint
app.get('/health', (req, res) => {
res.json({ status: 'ok', timestamp: new Date().toISOString() });
});
// API routes
app.use('/api/passport/domain', domainRoutes);
app.use('/api/messaging', messagingRoutes);
app.use('/api/gameforge', gameforgeRoutes);
// Initialize Socket.io
const io = socketService.initialize(httpServer);
app.set('io', io); // Make io available in routes
// 404 handler
app.use((req, res) => {
res.status(404).json({
success: false,
error: 'Endpoint not found'
});
});
// Error handler
app.use((err, req, res, next) => {
console.error('Server error:', err);
res.status(500).json({
success: false,
error: process.env.NODE_ENV === 'development' ? err.message : 'Internal server error'
});
});
// Start server
httpServer.listen(PORT, () => {
console.log(`
╔═══════════════════════════════════════════════════════╗
║ AeThex Connect - Communication Platform ║
║ Server running on port ${PORT}
║ Environment: ${process.env.NODE_ENV || 'development'}
╚═══════════════════════════════════════════════════════╝
`);
console.log(`Health check: http://localhost:${PORT}/health`);
console.log(`API Base URL: http://localhost:${PORT}/api`);
console.log(`Socket.io: Enabled`);
});
// Graceful shutdown
process.on('SIGTERM', () => {
console.log('SIGTERM received, shutting down gracefully...');
process.exit(0);
});
process.on('SIGINT', () => {
console.log('SIGINT received, shutting down gracefully...');
process.exit(0);
});
module.exports = app;