This commit is contained in:
2025-07-12 12:45:33 +08:00
parent 8daa71e7c1
commit 8404f4f1cf
5 changed files with 154 additions and 10 deletions

40
app.js Normal file
View File

@ -0,0 +1,40 @@
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
// 基本的Hello World路由
app.get('/', (req, res) => {
res.json({
message: 'Hello World from Node.js Docker! 🎉',
timestamp: new Date().toISOString(),
version: '1.0.0'
});
});
// 健康检查路由
app.get('/health', (req, res) => {
res.json({
status: 'healthy',
uptime: process.uptime(),
timestamp: new Date().toISOString()
});
});
// 启动服务器
app.listen(port, '0.0.0.0', () => {
console.log(`🚀 Hello World 应用启动成功!`);
console.log(`📡 服务器运行在 http://0.0.0.0:${port}`);
console.log(`🎯 访问 http://localhost:${port} 查看Hello World`);
console.log(`💚 访问 http://localhost:${port}/health 查看健康状态`);
});
// 优雅关闭
process.on('SIGTERM', () => {
console.log('📴 收到SIGTERM信号正在关闭服务器...');
process.exit(0);
});
process.on('SIGINT', () => {
console.log('📴 收到SIGINT信号正在关闭服务器...');
process.exit(0);
});