89 lines
2.7 KiB
Docker
89 lines
2.7 KiB
Docker
# Minimal self-contained Dockerfile - no external files needed
|
|
FROM node:16-alpine
|
|
|
|
# Create app directory
|
|
WORKDIR /app
|
|
|
|
# Create a simple server.js file directly in the container
|
|
RUN echo '// Simple HTTP server\n\
|
|
const http = require("http");\n\
|
|
const fs = require("fs");\n\
|
|
const path = require("path");\n\
|
|
\n\
|
|
// Create directory for HTML file\n\
|
|
fs.mkdirSync(path.join(__dirname, "public"), { recursive: true });\n\
|
|
\n\
|
|
// Create HTML content\n\
|
|
const html = `<!DOCTYPE html>\n\
|
|
<html>\n\
|
|
<head>\n\
|
|
<title>My Favorites - Maintenance</title>\n\
|
|
<meta charset="UTF-8">\n\
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">\n\
|
|
<style>\n\
|
|
body { font-family: sans-serif; background: #f5f5f0; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }\n\
|
|
.container { max-width: 600px; padding: 40px; background: white; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); text-align: center; }\n\
|
|
h1 { color: #3b82f6; }\n\
|
|
</style>\n\
|
|
</head>\n\
|
|
<body>\n\
|
|
<div class="container">\n\
|
|
<h1>My Favorites</h1>\n\
|
|
<p>Our application is currently undergoing maintenance.</p>\n\
|
|
<p>We will be back shortly with a collection of books, movies, series, and more that have made an impression.</p>\n\
|
|
<p>Thank you for your patience!</p>\n\
|
|
</div>\n\
|
|
</body>\n\
|
|
</html>`;\n\
|
|
\n\
|
|
// Write HTML to file\n\
|
|
fs.writeFileSync(path.join(__dirname, "public", "index.html"), html);\n\
|
|
\n\
|
|
// Create server\n\
|
|
const server = http.createServer((req, res) => {\n\
|
|
// Log request\n\
|
|
console.log(`${new Date().toISOString()} - ${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 HTML for all other routes\n\
|
|
fs.readFile(path.join(__dirname, "public", "index.html"), (err, content) => {\n\
|
|
if (err) {\n\
|
|
res.writeHead(500);\n\
|
|
res.end("Error loading page");\n\
|
|
console.error("Error:", err);\n\
|
|
return;\n\
|
|
}\n\
|
|
\n\
|
|
res.writeHead(200, { "Content-Type": "text/html" });\n\
|
|
res.end(content);\n\
|
|
});\n\
|
|
});\n\
|
|
\n\
|
|
// Start server\n\
|
|
const PORT = process.env.PORT || 3000;\n\
|
|
server.listen(PORT, "0.0.0.0", () => {\n\
|
|
console.log(`Server running on port ${PORT}`);\n\
|
|
});\n\
|
|
\n\
|
|
// Handle errors\n\
|
|
process.on("uncaughtException", (err) => {\n\
|
|
console.error("Uncaught exception:", err);\n\
|
|
});\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"]
|