This commit is contained in:
greg 2025-04-27 21:46:22 +02:00
parent f3e87f2b9c
commit 7ce9623467
5 changed files with 63 additions and 61 deletions

View File

@ -1 +1 @@
web: npm start
web: node server.js

View File

@ -1,5 +1,5 @@
[phases.setup]
nixPkgs = ["nodejs", "nodejs.pkgs.pnpm"]
nixPkgs = ["nodejs"]
[phases.install]
cmds = ["npm ci"]
@ -8,9 +8,8 @@ cmds = ["npm ci"]
cmds = ["npm run build"]
[start]
cmd = "npm start"
cmd = "node server.js"
[variables]
NODE_ENV = "production"
PORT = "3000"
HOST = "0.0.0.0"

View File

@ -5,7 +5,7 @@
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "NODE_ENV=production node server.js",
"start": "node server.js",
"lint": "next lint"
},
"dependencies": {

View File

@ -1,66 +1,65 @@
// Simple Express server for more reliable deployment
const express = require('express');
const next = require('next');
/**
* Extremely simplified server for Next.js
*/
// Basic HTTP server
const http = require('http');
const fs = require('fs');
const path = require('path');
// Set up environment variables with defaults
const dev = process.env.NODE_ENV !== 'production';
const port = parseInt(process.env.PORT || '3000', 10);
// Port configuration
const PORT = process.env.PORT || 3000;
// Create the Next.js app instance with minimal configuration
const app = next({ dev });
const handle = app.getRequestHandler();
// Simple static file server
const server = http.createServer((req, res) => {
console.log(`Request received: ${req.method} ${req.url}`);
// Log memory usage for debugging
const logMemoryUsage = () => {
const memoryUsage = process.memoryUsage();
console.log('Memory usage:');
console.log(` RSS: ${Math.round(memoryUsage.rss / 1024 / 1024)} MB`);
console.log(` Heap total: ${Math.round(memoryUsage.heapTotal / 1024 / 1024)} MB`);
console.log(` Heap used: ${Math.round(memoryUsage.heapUsed / 1024 / 1024)} MB`);
};
// 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);
});
});
// Handle uncaught exceptions
process.on('uncaughtException', (err) => {
console.error('Uncaught exception:', err);
logMemoryUsage();
});
process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
logMemoryUsage();
process.on('unhandledRejection', (reason) => {
console.error('Unhandled rejection:', reason);
});
// Simple health check response
const healthCheck = (req, res) => {
res.status(200).json({ status: 'ok', timestamp: new Date().toISOString() });
};
app.prepare()
.then(() => {
const server = express();
// Add health check endpoint
server.get('/health', healthCheck);
server.get('/api/health', healthCheck);
// Serve static files from the public directory
server.use(express.static(path.join(__dirname, 'public')));
// Let Next.js handle all other routes
server.all('*', (req, res) => {
return handle(req, res);
});
// Start the server
server.listen(port, '0.0.0.0', (err) => {
if (err) throw err;
console.log(`> Ready on port ${port} - env ${process.env.NODE_ENV || 'development'}`);
logMemoryUsage();
});
})
.catch((ex) => {
console.error('An error occurred starting the app:', ex);
logMemoryUsage();
process.exit(1);
});

View File

@ -0,0 +1,4 @@
#!/bin/bash
# Simple startup script to ensure proper environment
export NODE_ENV=production
node server.js