From 570808d94c292fc664c4cd91bd9193e1d3aa9b7a Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Tue, 23 Oct 2018 15:34:10 +0200 Subject: [PATCH 1/2] ADD timeout to update check && ADD version to update check for future use --- lib/core/src/server/build-dev.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/core/src/server/build-dev.js b/lib/core/src/server/build-dev.js index 4b69603d86d0..7ddd0211afd7 100644 --- a/lib/core/src/server/build-dev.js +++ b/lib/core/src/server/build-dev.js @@ -77,7 +77,7 @@ function applyStatic(app, options) { } } -const updateCheck = async () => { +const updateCheck = async version => { let result; const time = Date.now(); try { @@ -85,7 +85,11 @@ const updateCheck = async () => { // if last check was more then 24h ago if (time - 86400000 > fromCache.time) { - const fromFetch = await fetch('https://storybooks.netlify.com/versions.json'); + const fromFetch = await Promise.race([ + fetch(`https://storybooks.netlify.com/versions.json?current=${version}`), + // if fetch is too slow, we won't wait for it + new Promise((res, rej) => global.setTimeout(rej, 1500)), + ]); const data = await fromFetch.json(); result = { success: true, data, time }; await cache.set('lastUpdateCheck', result); @@ -140,7 +144,11 @@ export async function buildDevStandalone(options) { const serverListening = listenToServer(server, listenAddr); - const [stats, updateInfo] = await Promise.all([webpackValid, updateCheck(), serverListening]); + const [stats, updateInfo] = await Promise.all([ + webpackValid, + updateCheck(options.packageJson.version), + serverListening, + ]); const proto = options.https ? 'https' : 'http'; const address = `${proto}://${options.host || 'localhost'}:${port}/`; const networkAddress = `${proto}://${ip.address()}:${port}/`; From c7bf9f2faa78112e4dd13f606a237d2d04be2430 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Tue, 23 Oct 2018 15:57:35 +0200 Subject: [PATCH 2/2] FIX url && IMPROVE table with extra ':' --- lib/core/src/server/build-dev.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/core/src/server/build-dev.js b/lib/core/src/server/build-dev.js index 7ddd0211afd7..25f3d2abf3b0 100644 --- a/lib/core/src/server/build-dev.js +++ b/lib/core/src/server/build-dev.js @@ -86,7 +86,7 @@ const updateCheck = async version => { // if last check was more then 24h ago if (time - 86400000 > fromCache.time) { const fromFetch = await Promise.race([ - fetch(`https://storybooks.netlify.com/versions.json?current=${version}`), + fetch(`https://storybook.js.org/versions.json?current=${version}`), // if fetch is too slow, we won't wait for it new Promise((res, rej) => global.setTimeout(rej, 1500)), ]); @@ -197,8 +197,8 @@ export async function buildDevStandalone(options) { }); serveMessage.push( - ['Local', chalk.cyan(address)], - ['On your network', chalk.cyan(networkAddress)] + ['Local:', chalk.cyan(address)], + ['On your network:', chalk.cyan(networkAddress)] ); // eslint-disable-next-line no-console