debug 4
This commit is contained in:
parent
f3e87f2b9c
commit
7ce9623467
@ -1 +1 @@
|
||||
web: npm start
|
||||
web: node server.js
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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": {
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
// Handle uncaught exceptions
|
||||
process.on('uncaughtException', (err) => {
|
||||
console.error('Uncaught exception:', err);
|
||||
logMemoryUsage();
|
||||
// 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);
|
||||
});
|
||||
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
|
||||
logMemoryUsage();
|
||||
});
|
||||
|
||||
// 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();
|
||||
server.listen(PORT, () => {
|
||||
console.log(`Server running on port ${PORT}`);
|
||||
console.log(`Environment: ${process.env.NODE_ENV || 'development'}`);
|
||||
});
|
||||
})
|
||||
.catch((ex) => {
|
||||
console.error('An error occurred starting the app:', ex);
|
||||
logMemoryUsage();
|
||||
process.exit(1);
|
||||
|
||||
// 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);
|
||||
});
|
||||
|
||||
4
my-favorites-app/start.sh
Normal file
4
my-favorites-app/start.sh
Normal file
@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
# Simple startup script to ensure proper environment
|
||||
export NODE_ENV=production
|
||||
node server.js
|
||||
Loading…
x
Reference in New Issue
Block a user