feat: 完善后端启动,打二进制文件防止因为网络无法运行
This commit is contained in:
@@ -76,25 +76,15 @@ async function startDenoBackend(isDev) {
|
||||
|
||||
if (isDev) {
|
||||
// 开发模式:使用项目中的Deno后端
|
||||
scriptPath = path.join(__dirname, "..", "..", "backend-deno", "main.ts");
|
||||
scriptPath = path.join(__dirname, "..", "..", "backend-deno", "dist", "backend-deno");
|
||||
} else {
|
||||
// 生产模式:使用打包的Deno后端
|
||||
scriptPath = path.join(process.resourcesPath, "backend-deno", "main.ts");
|
||||
scriptPath = path.join(process.resourcesPath, "backend", "backend-deno");
|
||||
}
|
||||
|
||||
console.log(`启动Deno后端: ${scriptPath} 在端口 ${backendPort}`);
|
||||
console.log(`后端脚本路径存在: ${fs.existsSync(scriptPath)}`);
|
||||
|
||||
// 检查Deno是否安装
|
||||
try {
|
||||
const denoCheck = spawn("deno", ["--version"], { stdio: "pipe" });
|
||||
denoCheck.on("error", (err) => {
|
||||
throw new Error(`Deno未安装或不在PATH中: ${err.message}`);
|
||||
});
|
||||
} catch (err) {
|
||||
throw new Error(`Deno未安装或不在PATH中: ${err.message}`);
|
||||
}
|
||||
|
||||
// 打印Deno脚本目录内容
|
||||
try {
|
||||
const scriptDir = path.dirname(scriptPath);
|
||||
@@ -104,29 +94,14 @@ async function startDenoBackend(isDev) {
|
||||
}
|
||||
|
||||
// 启动子进程
|
||||
denoProcess = spawn(
|
||||
"deno",
|
||||
[
|
||||
"run",
|
||||
"--allow-net",
|
||||
"--allow-run",
|
||||
"--allow-read",
|
||||
"--allow-write",
|
||||
"--allow-env",
|
||||
scriptPath,
|
||||
],
|
||||
denoProcess = spawn(scriptPath,
|
||||
[],
|
||||
{
|
||||
env: { ...process.env, PORT: backendPort.toString() },
|
||||
env: { ...process.env, PORT: backendPort.toString(), USER_DATA_DIR: require("electron").app.getPath("userData"), },
|
||||
stdio: "pipe", // 确保可以读取标准输出和错误
|
||||
}
|
||||
);
|
||||
|
||||
// 输出Deno进程的日志
|
||||
denoProcess.stdout.on("data", (data) => {
|
||||
const output = data.toString().trim();
|
||||
console.log(`Deno后端输出: ${output}`);
|
||||
});
|
||||
|
||||
denoProcess.stderr.on("data", (data) => {
|
||||
const message = data.toString().trim();
|
||||
// 判断是否是错误日志还是普通日志
|
||||
|
||||
Reference in New Issue
Block a user