added config file
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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});
|
||||
}
|
||||
}
|
||||
5
src/config/config.js
Normal file
5
src/config/config.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const getConfig = () => {
|
||||
return window._env_ || {};
|
||||
}
|
||||
|
||||
export default getConfig;
|
||||
Reference in New Issue
Block a user