fix: improve Next.js server increase timeout for server readiness

This commit is contained in:
shiva raj badu 2026-03-24 10:57:02 +05:45
parent 93ef13604a
commit 287bc6bd69
No known key found for this signature in database
5 changed files with 1056 additions and 7 deletions

Binary file not shown.

4
electron/.gitignore vendored
View file

@ -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/

View file

@ -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) {

File diff suppressed because one or more lines are too long

Binary file not shown.