fix: config.json丢失引起编辑器白屏

This commit is contained in:
unanmed 2023-09-25 18:01:06 +08:00
parent b7b382611d
commit e0fe4be7bc

View File

@ -582,6 +582,14 @@ async function startWsServer(http: Server) {
}); });
} }
async function ensureConfig() {
try {
fs.readFile(resolvePath('_server/config.json'));
} catch {
fs.writeFile(resolvePath('_server/config.json'), '{}', 'utf-8');
}
}
(async function () { (async function () {
// 1. 启动vite服务 // 1. 启动vite服务
const vite = await createServer(); const vite = await createServer();
@ -589,6 +597,7 @@ async function startWsServer(http: Server) {
console.log(`游戏地址http://localhost:5173/games/${config.name}/`); console.log(`游戏地址http://localhost:5173/games/${config.name}/`);
// 2. 启动样板http服务 // 2. 启动样板http服务
await ensureConfig();
const server = await startHttpServer(3000); const server = await startHttpServer(3000);
// 3. 启动样板ws热重载服务 // 3. 启动样板ws热重载服务