const express = require('express');
const path = require('path');
const app = express();
const PORT = process.env.PORT || 8080;
const ROOT = __dirname;
// 首页 —— 全屏启动页面
// 必须在静态文件中间件之前注册,否则 express.static 会优先返回 index.html
app.get('/', (req, res) => {
res.send(`
运动伤害现场急救虚拟仿真实验
运动伤害现场急救虚拟仿真实验
VIRTUAL SIMULATION EXPERIMENT
点击按钮进入全屏沉浸式实验环境
`);
});
// 静态文件服务
app.use(express.static(ROOT, {
setHeaders: (res, filePath) => {
// 确保 .wasm 有正确的 MIME type(Chrome 需要)
if (filePath.endsWith('.wasm')) {
res.setHeader('Content-Type', 'application/wasm');
}
if (filePath.endsWith('.js')) {
res.setHeader('Content-Type', 'application/javascript');
}
}
}));
// 启动服务
app.listen(PORT, () => {
console.log('');
console.log(' ╔══════════════════════════════════════════════════╗');
console.log(' ║ 运动伤害现场急救虚拟仿真实验 - WebGL Server ║');
console.log(' ║ ║');
console.log(' ║ Server running at: http://localhost:' + PORT + ' ║');
console.log(' ║ Press Ctrl+C to stop ║');
console.log(' ╚══════════════════════════════════════════════════╝');
console.log('');
});