diff --git a/my-favorites-app/Procfile b/my-favorites-app/Procfile new file mode 100644 index 0000000..063b78f --- /dev/null +++ b/my-favorites-app/Procfile @@ -0,0 +1 @@ +web: npm start diff --git a/my-favorites-app/package.json b/my-favorites-app/package.json index 07a5a96..1274c21 100644 --- a/my-favorites-app/package.json +++ b/my-favorites-app/package.json @@ -17,6 +17,7 @@ "class-variance-authority": "^0.7.0", "clsx": "^2.1.0", "date-fns": "^3.3.1", + "express": "^4.18.2", "lucide-react": "^0.358.0", "next": "14.1.0", "react": "^18.2.0", diff --git a/my-favorites-app/server.js b/my-favorites-app/server.js index 7e3faa2..3f6a140 100644 --- a/my-favorites-app/server.js +++ b/my-favorites-app/server.js @@ -1,39 +1,66 @@ -const { createServer } = require('http'); -const { parse } = require('url'); +// Simple Express server for more reliable deployment +const express = require('express'); const next = require('next'); +const path = require('path'); +// Set up environment variables with defaults const dev = process.env.NODE_ENV !== 'production'; -const hostname = process.env.HOSTNAME || '0.0.0.0'; const port = parseInt(process.env.PORT || '3000', 10); -// Prepare the Next.js app -const app = next({ dev, hostname, port }); +// Create the Next.js app instance with minimal configuration +const app = next({ dev }); const handle = app.getRequestHandler(); -app.prepare().then(() => { - console.log(`Next.js App is preparing to start...`); - - createServer(async (req, res) => { - try { - // Parse the URL - const parsedUrl = parse(req.url, true); - - // Let Next.js handle the request - await handle(req, res, parsedUrl); - } catch (err) { - console.error('Error occurred handling request:', err); - res.statusCode = 500; - res.end('Internal Server Error'); - } - }) - .once('error', (err) => { - console.error('Server error:', err); - process.exit(1); - }) - .listen(port, hostname, () => { - console.log(`> Ready on http://${hostname}:${port}`); - }); -}).catch((err) => { - console.error('Next.js app preparation failed:', err); - process.exit(1); +// 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`); +}; + +// 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(); +}); + +// 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); + }); diff --git a/my-favorites-app/src/app/index.html b/my-favorites-app/src/app/index.html new file mode 100644 index 0000000..6ede5b1 --- /dev/null +++ b/my-favorites-app/src/app/index.html @@ -0,0 +1,45 @@ + + + + + + My Favorites - Maintenance + + + +
+

My Favorites

+

Our application is currently undergoing maintenance. We'll be back shortly with a collection of books, movies, series, and more that have made an impression.

+

Thank you for your patience!

+
+ + diff --git a/my-favorites-app/src/app/layout.tsx b/my-favorites-app/src/app/layout.tsx index e196398..6b14db9 100644 --- a/my-favorites-app/src/app/layout.tsx +++ b/my-favorites-app/src/app/layout.tsx @@ -1,16 +1,11 @@ import type { Metadata } from "next"; -import { Geist, Geist_Mono } from "next/font/google"; -import { Header } from "@/components/Header"; +import { Inter } from "next/font/google"; import "./globals.css"; -const geistSans = Geist({ - variable: "--font-geist-sans", - subsets: ["latin"], -}); - -const geistMono = Geist_Mono({ - variable: "--font-geist-mono", +// Use Inter font instead of Geist for better compatibility +const inter = Inter({ subsets: ["latin"], + display: "swap", }); export const metadata: Metadata = { @@ -25,11 +20,22 @@ export default function RootLayout({ }>) { return ( - +
-
+
+
+
+ + My Favorites + +
+
+ +
+
+
{children}