From 7869b6fd7f53758e4ae2388c2b6ca534d6d1fbd6 Mon Sep 17 00:00:00 2001 From: swve Date: Tue, 11 Apr 2023 23:13:32 +0200 Subject: [PATCH] feat: use env variables for backend values --- front/services/config/config.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/front/services/config/config.ts b/front/services/config/config.ts index 8e9a63a6..401b7000 100644 --- a/front/services/config/config.ts +++ b/front/services/config/config.ts @@ -1,5 +1,7 @@ -const LEARNHOUSE_API_URL = "http://localhost:1338/api/"; -const LEARNHOUSE_BACKEND_URL = "http://localhost:1338/"; +const LEARNHOUSE_HTTP_PROTOCOL = process.env.NEXT_PUBLIC_LEARNHOUSE_HTTPS === "true" ? "https://" : "http://"; +const LEARNHOUSE_API_URL = `${process.env.NEXT_PUBLIC_LEARNHOUSE_API_URL}`; +const LEARNHOUSE_BACKEND_URL = `${process.env.NEXT_PUBLIC_LEARNHOUSE_BACKEND_URL}`; +const LEARNHOUSE_DOMAIN = process.env.NEXT_PUBLIC_LEARNHOUSE_DOMAIN; export const getAPIUrl = () => LEARNHOUSE_API_URL; export const getBackendUrl = () => LEARNHOUSE_BACKEND_URL; @@ -7,11 +9,10 @@ export const getSelfHostedOption = () => (process.env.NEXT_PUBLIC_LEARNHOUSE_SEL export const getUriWithOrg = (orgslug: string, path: string) => { const selfHosted = getSelfHostedOption(); - if (selfHosted) { - return `http://localhost:3000${path}`; + return `${LEARNHOUSE_DOMAIN}${path}`; } - return `http://${orgslug}.localhost:3000${path}`; + return `${LEARNHOUSE_HTTP_PROTOCOL}${orgslug}.${LEARNHOUSE_DOMAIN}${path}`; }; export const getOrgFromUri = () => { @@ -21,8 +22,8 @@ export const getOrgFromUri = () => { } else { if (typeof window !== "undefined") { const hostname = window.location.hostname; - - return hostname.replace(".localhost", ""); + + return hostname.replace(`.${LEARNHOUSE_DOMAIN}`, ""); } } };