70 lines
2.0 KiB
JavaScript
70 lines
2.0 KiB
JavaScript
const express = require('express');
|
|
const path = require('path');
|
|
const app = express();
|
|
const PORT = 5000;
|
|
|
|
// 静态文件服务
|
|
app.use(express.static(path.join(__dirname, '../frontend/dist')));
|
|
|
|
// 健康检查
|
|
app.get('/api/health', (req, res) => {
|
|
res.json({
|
|
success: true,
|
|
message: '端口5000测试服务',
|
|
version: '1.0.0',
|
|
timestamp: new Date().toISOString(),
|
|
bind_address: '0.0.0.0',
|
|
port: PORT,
|
|
status: 'running'
|
|
});
|
|
});
|
|
|
|
// 测试页面
|
|
app.get('/test-5000', (req, res) => {
|
|
res.send(`
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head><title>端口5000测试</title><meta charset="utf-8"></head>
|
|
<body style="font-family: Arial; padding: 40px;">
|
|
<h1>✅ 端口5000测试成功!</h1>
|
|
<p>服务器: 43.161.248.209:${PORT}</p>
|
|
<p>绑定地址: 0.0.0.0</p>
|
|
<p>状态: <span style="color: green; font-weight: bold;">运行正常</span></p>
|
|
|
|
<div style="background: #f0f8ff; padding: 20px; border-radius: 10px; margin: 20px 0;">
|
|
<h2>🔗 系统链接:</h2>
|
|
<ul>
|
|
<li><a href="http://43.161.248.209:3000/">主系统 (端口3000)</a></li>
|
|
<li><a href="/api/health">5000端口健康检查</a></li>
|
|
<li><a href="http://43.161.248.209:3000/api/health">3000端口API</a></li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
`);
|
|
});
|
|
|
|
// 默认路由
|
|
app.get('/', (req, res) => {
|
|
res.redirect('/test-5000');
|
|
});
|
|
|
|
// 启动服务器 - 明确绑定到0.0.0.0
|
|
const server = app.listen(PORT, '0.0.0.0', () => {
|
|
const address = server.address();
|
|
console.log(`
|
|
🔧 端口5000测试服务器
|
|
=============================
|
|
📍 绑定地址: ${address.address}:${address.port}
|
|
🌐 外部访问: http://43.161.248.209:${PORT}
|
|
🔗 测试页面: http://43.161.248.209:${PORT}/test-5000
|
|
✅ 明确绑定到: 0.0.0.0
|
|
=============================
|
|
`);
|
|
});
|
|
|
|
// 错误处理
|
|
server.on('error', (err) => {
|
|
console.error('服务器启动错误:', err);
|
|
});
|