const http = require('http'); const fs = require('fs'); const path = require('path'); const PORT = process.env.PORT || 24710; const HOST = process.env.HOST || '0.0.0.0'; const ROOT = __dirname; const MIME = { '.html': 'text/html; charset=utf-8', '.js': 'application/javascript', '.wasm': 'application/wasm', '.data': 'application/octet-stream', '.css': 'text/css', '.png': 'image/png', '.ico': 'image/x-icon', '.svg': 'image/svg+xml', '.json': 'application/json', '.jpg': 'image/jpeg', }; function extType(p) { return MIME[path.extname(p).toLowerCase()] || 'application/octet-stream'; } function headersForFile(fp, data) { const headers = { 'Content-Type': extType(fp), 'Content-Length': data.length, 'X-Content-Type-Options': 'nosniff', }; if (fp.endsWith('.unityweb')) { const originalPath = fp.slice(0, -'.unityweb'.length); headers['Content-Type'] = extType(originalPath); headers['Content-Encoding'] = data[0] === 0x1f && data[1] === 0x8b ? 'gzip' : 'br'; headers['Cache-Control'] = 'public, max-age=604800'; } else if (fp.endsWith('.loader.js')) { headers['Cache-Control'] = 'no-cache'; } else { headers['Cache-Control'] = 'public, max-age=3600'; } return headers; } // 首页:基于原始 index.html,注入启动封面(不修改任何 Unity 加载逻辑) function serveIndex(res) { try { let html = fs.readFileSync(path.join(ROOT, 'index.html'), 'utf-8'); // 注入到 之前的 CSS const css = ` `; // 注入到
最前面的 overlay const overlay = `VIRTUAL SIMULATION EXPERIMENT
点击按钮进入全屏沉浸式实验环境