Files
val-blog/gch3n-infra/app/server.js
T

71 lines
2.2 KiB
JavaScript

const http = require('http');
const PORT = process.env.PORT || 3000;
const COLOR = process.env.DEPLOY_COLOR || 'unknown';
const VERSION = process.env.npm_package_version || '1.0.0';
const server = http.createServer((req, res) => {
const url = req.url;
// 健康检查端点
if (url === '/health') {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
status: 'healthy',
color: COLOR,
version: VERSION,
timestamp: new Date().toISOString(),
uptime: process.uptime()
}));
return;
}
// 主页
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(`
<!DOCTYPE html>
<html>
<head>
<title>gch3n.online</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 40px 20px;
background: ${COLOR === 'blue' ? '#e3f2fd' : '#e8f5e9'};
}
.badge {
display: inline-block;
padding: 4px 12px;
border-radius: 12px;
font-size: 12px;
font-weight: bold;
text-transform: uppercase;
background: ${COLOR === 'blue' ? '#1976d2' : '#388e3c'};
color: white;
}
h1 { color: #333; }
.info { color: #666; margin-top: 20px; }
</style>
</head>
<body>
<h1>🚀 gch3n.online</h1>
<span class="badge">${COLOR}</span>
<p>蓝绿部署示例应用</p>
<div class="info">
<p>版本: ${VERSION}</p>
<p>端口: ${PORT}</p>
<p>时间: ${new Date().toLocaleString('zh-CN')}</p>
</div>
</body>
</html>
`);
});
server.listen(PORT, () => {
console.log(`🚀 服务器运行在端口 ${PORT}`);
console.log(`🎨 部署颜色: ${COLOR}`);
console.log(`📦 版本: ${VERSION}`);
});