From f78deffbd5bccb5b34f42855152b0ce8958303cf Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Sun, 13 Oct 2019 16:13:09 +0300 Subject: [PATCH] next-lib requestGet fix & refactoring --- src/next-lib.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/next-lib.js b/src/next-lib.js index 8d572ed2..d185ebc1 100644 --- a/src/next-lib.js +++ b/src/next-lib.js @@ -1,3 +1,5 @@ +import axios from 'axios' + export async function requestGet(url, defaultResponse) { try { const res = await axios.get(url) @@ -15,14 +17,14 @@ export function createApiUrl(req, path) { } function absoluteUrl(req, defaultLocalhost) { - var protocol = 'https:'; - var host = req + let protocol = 'https:' + let host = req ? (req.headers['x-forwarded-host'] || req.headers['host']) - : window.location.host; + : window.location.host host = host || defaultLocalhost if (host.indexOf('localhost') > -1) { - if (defaultLocalhost) host = defaultLocalhost; - protocol = 'http:'; + if (defaultLocalhost) host = defaultLocalhost + protocol = 'http:' } return {