Files
action_test/app.js
2025-07-12 12:45:33 +08:00

40 lines
1.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
});