From d1e65fffb1087cbe695b215c8d57702d1672e09d Mon Sep 17 00:00:00 2001 From: Karel Hala <khala@redhat.com> Date: Sat, 4 Apr 2020 13:51:53 +0200 Subject: [PATCH] Add all available APIs --- src/api_keys.json | 14 ++++++++++++++ src/utils/api.js | 25 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/api_keys.json diff --git a/src/api_keys.json b/src/api_keys.json new file mode 100644 index 0000000..04493bc --- /dev/null +++ b/src/api_keys.json @@ -0,0 +1,14 @@ +{ + "air": { + "apiBase": "https://muniair-f106.restdb.io", + "key": "5e0ef5cbb68f0802dd3e5f4d" + }, + "sun": { + "apiBase": "https://munisun-d71a.restdb.io", + "key": "5df0aababf46220df655d9df" + }, + "temp": { + "apiBase": "https://munitest-16ae.restdb.io", + "key": "5dc7d91d64e7774913b6eaf8" + } +} diff --git a/src/utils/api.js b/src/utils/api.js index c46f608..8002266 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -1,5 +1,29 @@ import axios from "axios"; import config from "../auth_config.json"; +import keys from "../api_keys.json"; + +const instances = Object.entries(keys).reduce( + (acc, [key, api]) => ({ + ...acc, + [key]: { + apiInstance: axios.create({ + baseURL: api.apiBase, + headers: { + "content-type": "application/json", + "x-apikey": api.key, + "cache-control": "no-cache" + } + }) + } + }), + {} +); + +Object.keys(instances).forEach((instanceKey) => { + instances[instanceKey].apiInstance.interceptors.response.use((response) => response.data || response); + instances[instanceKey].get = (path) => instances[instanceKey].apiInstance.get(path); + instances[instanceKey].post = (path, payload) => instances[instanceKey].apiInstance.post(path, payload); +}); const apiHeaders = { "content-type": "application/json", @@ -15,6 +39,7 @@ const apiInstance = axios.create({ apiInstance.interceptors.response.use((response) => response.data || response); const Api = { + ...instances, get: (path) => apiInstance.get(path), post: (path, payload) => apiInstance.post(path, payload) }; -- GitLab