refactor(server): 动态导入open模块以优化启动性能

- 将open模块的引入方式从同步改为动态导入
- 避免在服务器启动时立即加载不必要的依赖
- 提升应用初始化速度和资源利用率
- 确保浏览器自动打开功能正常运行
- 添加错误处理以应对模块加载失败情况
This commit is contained in:
coolxitech
2025-12-13 13:53:53 +08:00
parent 1b2718246f
commit c0b405ae98

View File

@@ -1,6 +1,5 @@
const express = require('express'); const express = require('express');
const path = require('node:path'); const path = require('node:path');
const openUrl = require('open');
const os = require('node:os'); const os = require('node:os');
const app = express(); const app = express();
@@ -37,6 +36,7 @@ const server = app.listen(0, HOST, async () => {
// 3. 自动打开浏览器 // 3. 自动打开浏览器
try { try {
const { default: openUrl } = await import('open');
await openUrl(url); await openUrl(url);
} catch (err) { } catch (err) {
console.error('无法自动打开浏览器:', err); console.error('无法自动打开浏览器:', err);