From a504d0b53a608042a6bb2b0505a2acc63bc78f25 Mon Sep 17 00:00:00 2001 From: b1ek Date: Fri, 5 May 2023 17:55:40 +1000 Subject: [PATCH] load api root path from a constant --- pairent_frontend_react/src/API/ApartamentService.js | 5 +++-- pairent_frontend_react/src/constants.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 pairent_frontend_react/src/constants.js diff --git a/pairent_frontend_react/src/API/ApartamentService.js b/pairent_frontend_react/src/API/ApartamentService.js index acfbb63..f4f0fe1 100644 --- a/pairent_frontend_react/src/API/ApartamentService.js +++ b/pairent_frontend_react/src/API/ApartamentService.js @@ -1,8 +1,9 @@ import axios from 'axios'; +const { API_ROOT } = require('../constants'); export default class ApartamentService { static async getAll(limit, offest) { - const response = await axios.get('http://127.0.0.1:8000/api/apartaments/', { + const response = await axios.get(API_ROOT + '/api/apartaments/', { params: { limit: limit, ...(offest !== 0 ? {offset: offest} : {}) @@ -12,7 +13,7 @@ export default class ApartamentService { } static async getById(id) { - const response = await axios.get('http://127.0.0.1:8000/api/apartament/' + id) + const response = await axios.get(API_ROOT + '/api/apartament/' + id) return response; } } \ No newline at end of file diff --git a/pairent_frontend_react/src/constants.js b/pairent_frontend_react/src/constants.js new file mode 100644 index 0000000..1555b96 --- /dev/null +++ b/pairent_frontend_react/src/constants.js @@ -0,0 +1,12 @@ +/** + * Api root path + * @type {string} + */ +const API_ROOT = + window.location.protocol + + + import.meta.env.DEV ? + '//127.0.0.1:8000' : + '//pairent.vvsu.ru'; + +module.exports = Object.freeze({ API_ROOT }); \ No newline at end of file