diff --git a/src/Authentification/Keycloak.js b/src/Authentification/Keycloak.js index 2cd6c28..29c12ce 100644 --- a/src/Authentification/Keycloak.js +++ b/src/Authentification/Keycloak.js @@ -1,4 +1,9 @@ import Keycloak from "keycloak-js"; +import getConfig from "../config/config"; + +const config = getConfig(); +const path = config.REACT_APP_KC_HOSTNAME || process.env.REACT_APP_KC_HOSTNAME; + const keycloak = new Keycloak({ url: process.env.REACT_APP_KC, realm: "Jodel", diff --git a/src/api/posts.api.js b/src/api/posts.api.js index 6f7f337..bb68dce 100644 --- a/src/api/posts.api.js +++ b/src/api/posts.api.js @@ -1,21 +1,25 @@ import axios from "axios" import {locationUtils} from "../utils/location"; import keycloak from "../Authentification/Keycloak"; +import getConfig from "../config/config"; + +const config = getConfig(); +const path = config.REACT_APP_API_HOSTNAME || process.env.REACT_APP_API_HOSTNAME; export const postApi = { async getPostsByCoords (lat, lon) { if (!keycloak.authenticated) return []; - return (await axios.get(`${process.env.REACT_APP_API}/posts/${lat}/${lon}`)).data; + return (await axios.get(`${route}/posts/${lat}/${lon}`)).data; }, async getPostByID (id) { if (!keycloak.authenticated) return []; - return (await axios.get(`${process.env.REACT_APP_API}/post/${id}`)).data; + return (await axios.get(`${path}/post/${id}`)).data; }, async createNewPost(title, content, parent = null) { const location = await locationUtils.getCurrentLocation(); if(location.lon && location.lat) { if(parent !== null) { - await axios.post(`${process.env.REACT_APP_API}/posts`, { + await axios.post(`${path}/posts`, { "authorID": 1, "title": title, "content": content, @@ -27,7 +31,7 @@ export const postApi = { "parent": parent }); } else { - await axios.post(`${process.env.REACT_APP_API}/posts`, { + await axios.post(`${path}/posts`, { "authorID": 1, "title": title, "content": content, @@ -43,6 +47,6 @@ export const postApi = { } }, async reactToPost(id, reaction) { - await axios.patch(`${process.env.REACT_APP_API}/post/${id}`, {reaction: reaction}); + await axios.patch(`${path}/post/${id}`, {reaction: reaction}); } } \ No newline at end of file diff --git a/src/config/config.js b/src/config/config.js new file mode 100644 index 0000000..fc436a9 --- /dev/null +++ b/src/config/config.js @@ -0,0 +1,5 @@ +const getConfig = () => { + return window._env_ || {}; +} + +export default getConfig; \ No newline at end of file