2025-04-27 21:46:22 +02:00

66 lines
1.7 KiB
JavaScript

/**
* Extremely simplified server for Next.js
*/
// Basic HTTP server
const http = require('http');
const fs = require('fs');
const path = require('path');
// Port configuration
const PORT = process.env.PORT || 3000;
// Simple static file server
const server = http.createServer((req, res) => {
console.log(`Request received: ${req.method} ${req.url}`);
// Health check endpoint
if (req.url === '/health' || req.url === '/api/health') {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ status: 'ok', timestamp: new Date().toISOString() }));
return;
}
// Serve static HTML as fallback
const indexPath = path.join(__dirname, 'src', 'app', 'index.html');
fs.readFile(indexPath, (err, content) => {
if (err) {
res.writeHead(500);
res.end('Error loading index.html');
console.error('Error serving index.html:', err);
return;
}
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(content);
});
});
// Start the server
server.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
console.log(`Environment: ${process.env.NODE_ENV || 'development'}`);
});
// Handle errors
server.on('error', (err) => {
console.error('Server error:', err);
});
// Handle process termination
process.on('SIGTERM', () => {
console.log('SIGTERM received, shutting down gracefully');
server.close(() => {
console.log('Server closed');
process.exit(0);
});
});
process.on('uncaughtException', (err) => {
console.error('Uncaught exception:', err);
});
process.on('unhandledRejection', (reason) => {
console.error('Unhandled rejection:', reason);
});