Skip to content

Commit c9ee8f5

Browse files
committed
use a call to chromium browser on startup to initialize webpack/nextjs websockets
- a very confusing thing about development of cocalc due to nextjs *AND* webpack doing separate hot module reloading for different apps in the same process is that when you restart the server you have to visit some nextjs landing page and wait 1-2 minutes for it to compile before the frontend app works. This commit fixes that by automating it, as long as you have chromium-browser installed.
1 parent 50074a2 commit c9ee8f5

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/packages/hub/hub.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,9 @@ async function startServer(): Promise<void> {
274274
});
275275

276276
const protocol = program.httpsKey ? "https" : "http";
277+
const target = `${protocol}://${program.hostname}:${port}${basePath}`;
277278

278-
const msg = `Started HUB!\n\n-----------\n\n The following URL *might* work: ${protocol}://${
279-
program.hostname
280-
}:${port}${basePath}\n\n\nPORT=${port}\nBASE_PATH=${basePath}\nPROTOCOL=${protocol}\n\n${
279+
const msg = `Started HUB!\n\n-----------\n\n The following URL *might* work: ${target}\n\n\nPORT=${port}\nBASE_PATH=${basePath}\nPROTOCOL=${protocol}\n\n${
281280
basePath.length <= 1
282281
? ""
283282
: "If you are developing cocalc inside of cocalc, take the URL of the host cocalc\nand append " +
@@ -286,6 +285,26 @@ async function startServer(): Promise<void> {
286285
}\n\n-----------\n\n`;
287286
winston.info(msg);
288287
console.log(msg);
288+
289+
if (
290+
program.websocketServer &&
291+
program.nextServer &&
292+
process.env["NODE_ENV"] != "production"
293+
) {
294+
// This is entirely to deal with conflicts between both nextjs and webpack when doing
295+
// hot module reloading. They fight with each other, and the we -- the developers --
296+
// win only AFTER the fight is done. So we force the fight automatically, rather than
297+
// manually, which is confusing.
298+
console.log(
299+
`launch get of ${target} so that webpack and nextjs websockets can fight things out`,
300+
);
301+
const process = spawn(
302+
"chromium-browser",
303+
["--no-sandbox", "--headless", target],
304+
{ detached: true, stdio: "ignore" },
305+
);
306+
process.unref();
307+
}
289308
}
290309

291310
if (program.all || program.mentions) {

0 commit comments

Comments
 (0)