-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathserver.js
More file actions
executable file
·29 lines (26 loc) · 1.01 KB
/
server.js
File metadata and controls
executable file
·29 lines (26 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const { config } = require('@fecommunity/reactpress-toolkit');
const cliProd = require('next/dist/cli/next-start');
const cliDev = require('next/dist/cli/next-dev');
const open = require('open');
const path = require('path');
const dotenv = require('dotenv');
// 最小化修复:确保环境变量正确加载
const projectRoot = process.env.REACTPRESS_ORIGINAL_CWD || process.cwd();
const envPath = path.join(projectRoot, '.env');
if (require('fs').existsSync(envPath)) {
dotenv.config({ path: envPath });
}
const port = config.CLIENT_PORT || 3001;
try {
// 这里根据环境判断,如果NODE_ENV=production, 就是生产
if (process.env.NODE_ENV === 'production') {
cliProd.nextStart(['-p', port]);
} else {
cliDev.nextDev(['-p', port]);
}
console.log(`[reactpress] 客户端已启动,端口:${port}`, `访问地址:http://localhost:${port}`);
// 尝试自动打开
open(`http://localhost:${port}`);
} catch (err) {
console.log(`[reactpress] 客户端启动失败!${err.message || err}`);
}