From 38e21ce12bdfe67383cce14fb578b2aca2892eea Mon Sep 17 00:00:00 2001 From: Masquerade Circus Date: Fri, 6 May 2022 15:58:47 -0500 Subject: [PATCH] refactor: minor refactor Minor refactor --- plugins/node.js | 4 +--- plugins/request.js | 24 +++++++++++++++++++++--- plugins/router.js | 3 ++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/plugins/node.js b/plugins/node.js index f1bc846..fc58290 100644 --- a/plugins/node.js +++ b/plugins/node.js @@ -78,7 +78,7 @@ async function inline(file, options = {}) { ...(options.esbuild || {}) }; - let result = esbuild.buildSync(esbuildOptions); + let result = await esbuild.build(esbuildOptions); if (options.compact) { let result2 = await terser.minify(result.outputFiles[1].text, { @@ -192,8 +192,6 @@ function icons(source, configuration = {}) { let { default: favicons } = require("favicons"), options = Object.assign({}, icons.options, configuration); - console.log(favicons); - if (options.iconsPath) { options.iconsPath = options.iconsPath.replace(/\/$/gi, "") + "/"; } diff --git a/plugins/request.js b/plugins/request.js index 0a7e87d..84c30de 100644 --- a/plugins/request.js +++ b/plugins/request.js @@ -93,10 +93,22 @@ function Request(baseUrl = "", options = {}) { } let response = await fetch(parseUrl(url, opts), innerOptions); - + let body = null; if (!response.ok) { let err = new Error(response.statusText); err.response = response; + if (/text/gi.test(acceptType)) { + err.body = await response.text(); + } + + if (/json/gi.test(acceptType)) { + try { + err.body = await response.json(); + } catch (error) { + // ignore + } + } + throw err; } @@ -105,11 +117,17 @@ function Request(baseUrl = "", options = {}) { } if (/text/gi.test(acceptType)) { - return response.text(); + body = await response.text(); + return body; } if (/json/gi.test(acceptType)) { - return response.json(); + try { + body = await response.json(); + return body; + } catch (error) { + // ignore + } } return response; diff --git a/plugins/router.js b/plugins/router.js index 0e78dba..8ad9fe9 100644 --- a/plugins/router.js +++ b/plugins/router.js @@ -204,7 +204,7 @@ class Router { window.history.pushState(null, null, path); } - if (v.current.component === component) { + if (v.isMounted && v.component.component === component) { return v.update(); } @@ -222,6 +222,7 @@ function plugin(vInstance) { routerOrComponent.container = elementContainer; routerOrComponent.v = v; + v.redirect = routerOrComponent.go.bind(routerOrComponent); // Activate the use of the router if (!v.isNodeJs) {