Add Docker setup with maintenance page and health check endpoint
This commit is contained in:
parent
57aaab43f1
commit
801e16c9af
@ -1,33 +1,6 @@
|
|||||||
# Versioning and metadata
|
# Ignore everything
|
||||||
.git
|
*
|
||||||
.gitignore
|
**/*
|
||||||
.dockerignore
|
|
||||||
|
|
||||||
# Build dependencies
|
# Except the Dockerfile itself
|
||||||
node_modules
|
!Dockerfile
|
||||||
npm-debug.log
|
|
||||||
|
|
||||||
# Environment (contains sensitive data)
|
|
||||||
.env
|
|
||||||
.env.*
|
|
||||||
!.env.example
|
|
||||||
|
|
||||||
# Files not required for production
|
|
||||||
README.md
|
|
||||||
Dockerfile
|
|
||||||
docker-compose.yml
|
|
||||||
*.log
|
|
||||||
.next
|
|
||||||
.vscode
|
|
||||||
.idea
|
|
||||||
*.md
|
|
||||||
*.log
|
|
||||||
*.lock
|
|
||||||
|
|
||||||
# Testing
|
|
||||||
coverage
|
|
||||||
.nyc_output
|
|
||||||
test
|
|
||||||
|
|
||||||
# Misc
|
|
||||||
.DS_Store
|
|
||||||
|
|||||||
@ -1,69 +1,48 @@
|
|||||||
# Self-contained Dockerfile that creates all necessary files
|
# Minimal self-contained Dockerfile - no external files needed
|
||||||
FROM node:16-alpine
|
FROM node:16-alpine
|
||||||
|
|
||||||
# Create app directory
|
# Create app directory
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Create server.js file directly in the Dockerfile
|
# Create a simple server.js file directly in the container
|
||||||
RUN echo 'const http = require("http");\n\
|
RUN echo '// Simple HTTP server\n\
|
||||||
|
const http = require("http");\n\
|
||||||
const fs = require("fs");\n\
|
const fs = require("fs");\n\
|
||||||
const path = require("path");\n\
|
const path = require("path");\n\
|
||||||
\n\
|
\n\
|
||||||
// Create the src/app directory if it doesn\'t exist\n\
|
// Create directory for HTML file\n\
|
||||||
fs.mkdirSync(path.join(__dirname, "src", "app"), { recursive: true });\n\
|
fs.mkdirSync(path.join(__dirname, "public"), { recursive: true });\n\
|
||||||
\n\
|
\n\
|
||||||
// Create a simple HTML file\n\
|
// Create HTML content\n\
|
||||||
const htmlContent = `<!DOCTYPE html>\n\
|
const html = `<!DOCTYPE html>\n\
|
||||||
<html lang="en">\n\
|
<html>\n\
|
||||||
<head>\n\
|
<head>\n\
|
||||||
|
<title>My Favorites - Maintenance</title>\n\
|
||||||
<meta charset="UTF-8">\n\
|
<meta charset="UTF-8">\n\
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">\n\
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">\n\
|
||||||
<title>My Favorites - Maintenance</title>\n\
|
|
||||||
<style>\n\
|
<style>\n\
|
||||||
body {\n\
|
body { font-family: sans-serif; background: #f5f5f0; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }\n\
|
||||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;\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\
|
||||||
background-color: #f5f5f0;\n\
|
h1 { color: #3b82f6; }\n\
|
||||||
color: #333;\n\
|
|
||||||
display: flex;\n\
|
|
||||||
flex-direction: column;\n\
|
|
||||||
align-items: center;\n\
|
|
||||||
justify-content: center;\n\
|
|
||||||
height: 100vh;\n\
|
|
||||||
margin: 0;\n\
|
|
||||||
padding: 20px;\n\
|
|
||||||
text-align: center;\n\
|
|
||||||
}\n\
|
|
||||||
.container {\n\
|
|
||||||
max-width: 600px;\n\
|
|
||||||
padding: 40px;\n\
|
|
||||||
background-color: white;\n\
|
|
||||||
border-radius: 8px;\n\
|
|
||||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);\n\
|
|
||||||
}\n\
|
|
||||||
h1 {\n\
|
|
||||||
color: #3b82f6;\n\
|
|
||||||
margin-bottom: 16px;\n\
|
|
||||||
}\n\
|
|
||||||
p {\n\
|
|
||||||
line-height: 1.6;\n\
|
|
||||||
margin-bottom: 24px;\n\
|
|
||||||
}\n\
|
|
||||||
</style>\n\
|
</style>\n\
|
||||||
</head>\n\
|
</head>\n\
|
||||||
<body>\n\
|
<body>\n\
|
||||||
<div class="container">\n\
|
<div class="container">\n\
|
||||||
<h1>My Favorites</h1>\n\
|
<h1>My Favorites</h1>\n\
|
||||||
<p>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.</p>\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\
|
<p>Thank you for your patience!</p>\n\
|
||||||
</div>\n\
|
</div>\n\
|
||||||
</body>\n\
|
</body>\n\
|
||||||
</html>`;\n\
|
</html>`;\n\
|
||||||
\n\
|
\n\
|
||||||
fs.writeFileSync(path.join(__dirname, "src", "app", "index.html"), htmlContent);\n\
|
// Write HTML to file\n\
|
||||||
|
fs.writeFileSync(path.join(__dirname, "public", "index.html"), html);\n\
|
||||||
\n\
|
\n\
|
||||||
// Create HTTP server\n\
|
// Create server\n\
|
||||||
const server = http.createServer((req, res) => {\n\
|
const server = http.createServer((req, res) => {\n\
|
||||||
console.log(`Request received: ${req.method} ${req.url}`);\n\
|
// Log request\n\
|
||||||
|
console.log(`${new Date().toISOString()} - ${req.method} ${req.url}`);\n\
|
||||||
\n\
|
\n\
|
||||||
// Health check endpoint\n\
|
// Health check endpoint\n\
|
||||||
if (req.url === "/health" || req.url === "/api/health") {\n\
|
if (req.url === "/health" || req.url === "/api/health") {\n\
|
||||||
@ -72,13 +51,12 @@ const server = http.createServer((req, res) => {\n\
|
|||||||
return;\n\
|
return;\n\
|
||||||
}\n\
|
}\n\
|
||||||
\n\
|
\n\
|
||||||
// Serve static HTML for all other routes\n\
|
// Serve HTML for all other routes\n\
|
||||||
const indexPath = path.join(__dirname, "src", "app", "index.html");\n\
|
fs.readFile(path.join(__dirname, "public", "index.html"), (err, content) => {\n\
|
||||||
fs.readFile(indexPath, (err, content) => {\n\
|
|
||||||
if (err) {\n\
|
if (err) {\n\
|
||||||
res.writeHead(500);\n\
|
res.writeHead(500);\n\
|
||||||
res.end("Error loading index.html");\n\
|
res.end("Error loading page");\n\
|
||||||
console.error("Error serving index.html:", err);\n\
|
console.error("Error:", err);\n\
|
||||||
return;\n\
|
return;\n\
|
||||||
}\n\
|
}\n\
|
||||||
\n\
|
\n\
|
||||||
@ -87,34 +65,17 @@ const server = http.createServer((req, res) => {\n\
|
|||||||
});\n\
|
});\n\
|
||||||
});\n\
|
});\n\
|
||||||
\n\
|
\n\
|
||||||
// Start the server\n\
|
// Start server\n\
|
||||||
const PORT = process.env.PORT || 3000;\n\
|
const PORT = process.env.PORT || 3000;\n\
|
||||||
server.listen(PORT, () => {\n\
|
server.listen(PORT, "0.0.0.0", () => {\n\
|
||||||
console.log(`Server running on port ${PORT}`);\n\
|
console.log(`Server running on port ${PORT}`);\n\
|
||||||
console.log(`Environment: ${process.env.NODE_ENV || "development"}`);\n\
|
|
||||||
});\n\
|
});\n\
|
||||||
\n\
|
\n\
|
||||||
// Handle errors\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\
|
process.on("uncaughtException", (err) => {\n\
|
||||||
console.error("Uncaught exception:", err);\n\
|
console.error("Uncaught exception:", err);\n\
|
||||||
});\n\
|
});\n\
|
||||||
\n\
|
' > server.js
|
||||||
process.on("unhandledRejection", (reason) => {\n\
|
|
||||||
console.error("Unhandled rejection:", reason);\n\
|
|
||||||
});' > server.js
|
|
||||||
|
|
||||||
# Set environment variables
|
# Set environment variables
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user