File size: 1,249 Bytes
59abb4f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
#!/usr/bin/env node
// Hits every route once so webpack compiles them before the user navigates.
// Run alongside the dev server: npm run prewarm

const ROUTES = ["/", "/screening", "/recruitment", "/dashboard", "/map", "/graph"];
const BASE = process.env.NEXT_PUBLIC_API_URL?.replace("/api", "") ?? "http://localhost:3000";

async function waitForServer(url, retries = 30) {
  for (let i = 0; i < retries; i++) {
    try {
      const r = await fetch(url, { signal: AbortSignal.timeout(3000) });
      if (r.ok || r.status < 500) return true;
    } catch {}
    await new Promise((r) => setTimeout(r, 2000));
  }
  return false;
}

const base = "http://localhost:3000";
console.log("Waiting for dev server…");
const up = await waitForServer(base);
if (!up) { console.error("Dev server never came up"); process.exit(1); }

console.log("Pre-warming routes (this compiles each page bundle once):");
for (const route of ROUTES) {
  const start = Date.now();
  try {
    await fetch(`${base}${route}`, { signal: AbortSignal.timeout(120_000) });
    console.log(`  ✓ ${route}${Date.now() - start}ms`);
  } catch (e) {
    console.log(`  ✗ ${route}${e.message}`);
  }
}
console.log("All routes compiled. Navigation will now be instant.");