# Self-contained Dockerfile that creates all necessary files FROM node:16-alpine # Create app directory WORKDIR /app # Create server.js file directly in the Dockerfile RUN echo 'const http = require("http");\n\ const fs = require("fs");\n\ const path = require("path");\n\ \n\ // Create the src/app directory if it doesn\'t exist\n\ fs.mkdirSync(path.join(__dirname, "src", "app"), { recursive: true });\n\ \n\ // Create a simple HTML file\n\ const htmlContent = `\n\ \n\ \n\ \n\ \n\ My Favorites - Maintenance\n\ \n\ \n\ \n\
\n\

My Favorites

\n\

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.

\n\

Thank you for your patience!

\n\
\n\ \n\ `;\n\ \n\ fs.writeFileSync(path.join(__dirname, "src", "app", "index.html"), htmlContent);\n\ \n\ // Create HTTP server\n\ const server = http.createServer((req, res) => {\n\ console.log(`Request received: ${req.method} ${req.url}`);\n\ \n\ // Health check endpoint\n\ if (req.url === "/health" || req.url === "/api/health") {\n\ res.writeHead(200, { "Content-Type": "application/json" });\n\ res.end(JSON.stringify({ status: "ok", timestamp: new Date().toISOString() }));\n\ return;\n\ }\n\ \n\ // Serve static HTML for all other routes\n\ const indexPath = path.join(__dirname, "src", "app", "index.html");\n\ fs.readFile(indexPath, (err, content) => {\n\ if (err) {\n\ res.writeHead(500);\n\ res.end("Error loading index.html");\n\ console.error("Error serving index.html:", err);\n\ return;\n\ }\n\ \n\ res.writeHead(200, { "Content-Type": "text/html" });\n\ res.end(content);\n\ });\n\ });\n\ \n\ // Start the server\n\ const PORT = process.env.PORT || 3000;\n\ server.listen(PORT, () => {\n\ console.log(`Server running on port ${PORT}`);\n\ console.log(`Environment: ${process.env.NODE_ENV || "development"}`);\n\ });\n\ \n\ // Handle errors\n\ server.on("error", (err) => {\n\ console.error("Server error:", err);\n\ });\n\ \n\ // Handle process termination\n\ process.on("SIGTERM", () => {\n\ console.log("SIGTERM received, shutting down gracefully");\n\ server.close(() => {\n\ console.log("Server closed");\n\ process.exit(0);\n\ });\n\ });\n\ \n\ process.on("uncaughtException", (err) => {\n\ console.error("Uncaught exception:", err);\n\ });\n\ \n\ process.on("unhandledRejection", (reason) => {\n\ console.error("Unhandled rejection:", reason);\n\ });' > server.js # Set environment variables ENV NODE_ENV=production ENV PORT=3000 # Expose the port EXPOSE 3000 # Start the server CMD ["node", "server.js"]