fix: improve Next.js server increase timeout for server readiness
This commit is contained in:
parent
93ef13604a
commit
287bc6bd69
5 changed files with 1056 additions and 7 deletions
BIN
electron/.cache/export-runtime/export-Linux-X64.zip
Normal file
BIN
electron/.cache/export-runtime/export-Linux-X64.zip
Normal file
Binary file not shown.
4
electron/.gitignore
vendored
4
electron/.gitignore
vendored
|
|
@ -21,4 +21,6 @@ app_dist
|
|||
resources/fastapi
|
||||
resources/nextjs
|
||||
dist
|
||||
servers/fastapi/fastembed_cache/
|
||||
servers/fastapi/fastembed_cache/
|
||||
electron/.cache/
|
||||
electron/.cache/export-runtime/
|
||||
|
|
@ -71,13 +71,12 @@ export async function startNextJsServer(
|
|||
let nextjsProcess;
|
||||
|
||||
if (isDev) {
|
||||
// Start NextJS development server
|
||||
nextjsProcess = spawn(
|
||||
"npm",
|
||||
["run", "dev", "--", "-p", port.toString()],
|
||||
{
|
||||
cwd: directory,
|
||||
stdio: ["inherit", "pipe", "pipe"],
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
env: { ...process.env, ...env },
|
||||
}
|
||||
);
|
||||
|
|
@ -97,6 +96,13 @@ export async function startNextJsServer(
|
|||
safeNextLog(data);
|
||||
console.error(`NextJS: ${data}`);
|
||||
});
|
||||
nextjsProcess.on("error", (err: Error) => {
|
||||
safeNextLog(`Spawn error: ${err.message}\n`);
|
||||
console.error(`NextJS spawn error: ${err.message}`);
|
||||
});
|
||||
nextjsProcess.on("exit", (code: number | null, signal: string | null) => {
|
||||
console.error(`NextJS process exited unexpectedly: code=${code}, signal=${signal}`);
|
||||
});
|
||||
} else {
|
||||
// Start NextJS build server
|
||||
nextjsProcess = await startNextjsBuildServer(directory, port);
|
||||
|
|
@ -125,19 +131,25 @@ function startNextjsBuildServer(directory: string, port: number): Promise<http.S
|
|||
}
|
||||
|
||||
|
||||
async function waitForServer(url: string, timeout = 30000): Promise<void> {
|
||||
async function waitForServer(url: string, timeout = 120000): Promise<void> {
|
||||
const startTime = Date.now();
|
||||
|
||||
while (Date.now() - startTime < timeout) {
|
||||
try {
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
http.get(url, (res) => {
|
||||
if (res.statusCode === 200 || res.statusCode === 304) {
|
||||
const req = http.get(url, (res) => {
|
||||
res.resume();
|
||||
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 500) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Error(`Unexpected status code: ${res.statusCode}`));
|
||||
}
|
||||
}).on('error', reject);
|
||||
});
|
||||
req.on('error', reject);
|
||||
req.setTimeout(5000, () => {
|
||||
req.destroy();
|
||||
reject(new Error('Request timed out'));
|
||||
});
|
||||
});
|
||||
return;
|
||||
} catch (error) {
|
||||
|
|
|
|||
1035
electron/resources/export/index.js
Normal file
1035
electron/resources/export/index.js
Normal file
File diff suppressed because one or more lines are too long
BIN
electron/resources/export/py/convert-linux-x64
Executable file
BIN
electron/resources/export/py/convert-linux-x64
Executable file
Binary file not shown.
Loading…
Add table
Reference in a new issue