From a2de94fd444fbccd44c4f4688e0e75ef1b8f8e69 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Fri, 27 Sep 2019 20:52:16 +0100 Subject: [PATCH] Fix getApiUrl implementation --- src/util.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/util.js b/src/util.js index b3cf464..6fc51fa 100644 --- a/src/util.js +++ b/src/util.js @@ -1,8 +1,16 @@ import config from "@/config"; import { ISO_DATE_REGEXP, EARTH_RADIUS_IN_KM } from "@/constants"; -export const getApiUrl = path => new URL(`${config.api.baseUrl}${path}`); +export const getApiUrl = path => { + const normalizedBaseUrl = config.api.baseUrl.endsWith("/") + ? config.api.baseUrl.slice(1) + : config.api.baseUrl; + const normalizedPath = path.startsWith("/") ? path : `/${path}`; + return `${normalizedBaseUrl}${normalizedPath}`; +}; + export const isIsoDate = s => ISO_DATE_REGEXP.test(s); + export const degreesToRadians = degrees => (degrees * Math.PI) / 180; // https://stackoverflow.com/a/365853/5952681