Initial commit: Template site for Start an AI Company deployment
- Node.js Express application with modern white UI - PostgreSQL and Redis integration - Docker Compose configuration without host port mappings - Traefik-ready with proper labels - Health check endpoint 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
75
server.js
Normal file
75
server.js
Normal file
@@ -0,0 +1,75 @@
|
||||
const express = require('express');
|
||||
const { Pool } = require('pg');
|
||||
const redis = require('redis');
|
||||
const path = require('path');
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
// PostgreSQL connection
|
||||
const pool = new Pool({
|
||||
host: process.env.POSTGRES_HOST || 'postgres',
|
||||
port: process.env.POSTGRES_PORT || 5432,
|
||||
user: process.env.POSTGRES_USER || 'postgres',
|
||||
password: process.env.POSTGRES_PASSWORD || 'postgres',
|
||||
database: process.env.POSTGRES_DB || 'template_db'
|
||||
});
|
||||
|
||||
// Redis connection
|
||||
const redisClient = redis.createClient({
|
||||
socket: {
|
||||
host: process.env.REDIS_HOST || 'redis',
|
||||
port: process.env.REDIS_PORT || 6379
|
||||
}
|
||||
});
|
||||
|
||||
// Connect to Redis
|
||||
redisClient.connect().catch(console.error);
|
||||
|
||||
// Test database connections
|
||||
pool.query('SELECT NOW()', (err, res) => {
|
||||
if (err) {
|
||||
console.error('PostgreSQL connection error:', err);
|
||||
} else {
|
||||
console.log('PostgreSQL connected successfully at:', res.rows[0].now);
|
||||
}
|
||||
});
|
||||
|
||||
redisClient.on('connect', () => {
|
||||
console.log('Redis connected successfully');
|
||||
});
|
||||
|
||||
redisClient.on('error', (err) => {
|
||||
console.error('Redis connection error:', err);
|
||||
});
|
||||
|
||||
// Serve static files
|
||||
app.use(express.static('public'));
|
||||
|
||||
// Health check endpoint
|
||||
app.get('/health', async (req, res) => {
|
||||
try {
|
||||
const pgResult = await pool.query('SELECT NOW()');
|
||||
await redisClient.ping();
|
||||
res.json({
|
||||
status: 'healthy',
|
||||
postgres: 'connected',
|
||||
redis: 'connected',
|
||||
timestamp: pgResult.rows[0].now
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
status: 'unhealthy',
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Main route
|
||||
app.get('/', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'public', 'index.html'));
|
||||
});
|
||||
|
||||
app.listen(PORT, '0.0.0.0', () => {
|
||||
console.log(`Server running on port ${PORT}`);
|
||||
});
|
||||
Reference in New Issue
Block a user