Fix Loading page

Summary:
The existing loading page was not behaving the way it was intended. The previous implementation triggered a page reload which made the whole retry mechanism useless.

Instead, a new endpoint was defined to expose whether the server is ready or not. Use this instead as a way of knowing whether we are good to reload the page.

Reviewed By: passy

Differential Revision: D49314749

fbshipit-source-id: eb67765d7deab8610fa5d31e710070da43a18c1c
This commit is contained in:
Lorenzo Blasa
2023-09-15 05:29:40 -07:00
committed by Facebook GitHub Bot
parent 045ccec154
commit 9e219b07d8
3 changed files with 17 additions and 5 deletions

View File

@@ -128,6 +128,11 @@ async function startHTTPServer(config: Config): Promise<{
});
});
app.get('/ready', (_req, res) => {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({isReady}));
});
app.get('/health', (_req, res) => {
res.end('flipper-ok');
});

View File

@@ -41,7 +41,10 @@ async function start() {
token = manifest.token;
}
console.info('Token is available: ' + token !== undefined && token?.length);
console.info(
'[flipper-client][ui-browser] Token is available: ',
token?.length,
);
const openPlugin = params.get('open-plugin');
if (openPlugin) {

View File

@@ -52,11 +52,15 @@
// the actual entry point instead of this page.
async function checkAndReload() {
try {
const response = await fetch('.');
if (response.status >= 200 && response.status < 500) {
const response = await fetch('/ready');
if (response.status >= 200 && response.status < 300) {
const data = await response.text();
const {isReady} = JSON.parse(data);
if (isReady) {
window.location.reload();
return;
}
}
} catch {
}
window.setTimeout(checkAndReload, 1000);