40 lines
1.0 KiB
JavaScript
40 lines
1.0 KiB
JavaScript
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);
|
||
});
|