Skip to content

Commit

Permalink
fix(server-dev): Add max count in waitForRestartedServer ping.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamTolmay committed Jun 24, 2022
1 parent 4c47ba6 commit d7d8a0b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/server-dev/lib/utils/waitForRestartedServer.js
Expand Up @@ -16,15 +16,21 @@

import request from './request.js';

const MAX_COUNT = 1200; // 10 mins

function waitForRestartedServer(basePath) {
let count = 0;
setTimeout(async () => {
try {
await request({
url: `${basePath}/api/ping`,
});
window.location.reload();
} catch (error) {
waitForRestartedServer(basePath);
count += 1;
if (count <= MAX_COUNT) {
waitForRestartedServer(basePath);
}
}
}, 500); // TODO: this ping should be shorter than rerender delay until we can pass a rebuild flag to reload.
}
Expand Down
1 change: 1 addition & 0 deletions packages/server-dev/manager/run.mjs
Expand Up @@ -81,6 +81,7 @@ async function run() {
const serverPromise = startServer(context);
await wait(800);
if (process.env.LOWDEFY_SERVER_DEV_OPEN_BROWSER === 'true') {
// TODO: Wait 1 sec for a ping and don't open if a ping is seen
opener(`http://localhost:${context.options.port}`);
}
await serverPromise;
Expand Down

0 comments on commit d7d8a0b

Please sign in to comment.