axiosApi
parent
b67b2f05c2
commit
0611020027
|
@ -1548,6 +1548,37 @@
|
|||
"integrity": "sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug==",
|
||||
"dev": true
|
||||
},
|
||||
"axios": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz",
|
||||
"integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==",
|
||||
"requires": {
|
||||
"follow-redirects": "1.5.10"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.5.10",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
|
||||
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
|
||||
"requires": {
|
||||
"debug": "=3.1.0"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
}
|
||||
}
|
||||
},
|
||||
"babel-eslint": {
|
||||
"version": "10.0.1",
|
||||
"resolved": "https://registry.npmjs.org/babel-eslint/-/babel-eslint-10.0.1.tgz",
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
"serve:build": "http-server ./build"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.19.2",
|
||||
"bootstrap": "4.3.1",
|
||||
"immer": "2.1.3",
|
||||
"prop-types": "15.7.2",
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
import axios from "axios";
|
||||
|
||||
function getHeaders() {
|
||||
return {
|
||||
"Content-Type": "application/json"
|
||||
};
|
||||
}
|
||||
|
||||
function internalRequest(url, options) {
|
||||
return axios
|
||||
.request(url, options)
|
||||
.then((res) => res.data)
|
||||
.catch(function (error) {
|
||||
if (error.response && error.response.data) {
|
||||
throw (
|
||||
{
|
||||
...error.response.data,
|
||||
message: error.response.data.detail || error.response.data.title
|
||||
} || error
|
||||
);
|
||||
}
|
||||
// The request was made but no response was received
|
||||
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
||||
// http.ClientRequest in node.js
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
export function post(url, data) {
|
||||
const options = {
|
||||
method: "post",
|
||||
data: JSON.stringify(data),
|
||||
headers: getHeaders()
|
||||
};
|
||||
|
||||
return internalRequest(url, options);
|
||||
}
|
||||
|
||||
export function put(url, data) {
|
||||
const options = {
|
||||
method: "put",
|
||||
data: JSON.stringify(data),
|
||||
headers: getHeaders()
|
||||
};
|
||||
|
||||
return internalRequest(url, options);
|
||||
}
|
||||
|
||||
export function del(url, data) {
|
||||
const options = {
|
||||
method: "delete",
|
||||
data: JSON.stringify(data),
|
||||
headers: getHeaders()
|
||||
};
|
||||
|
||||
return internalRequest(url, options);
|
||||
}
|
||||
|
||||
export function get(url) {
|
||||
const options = {
|
||||
method: "GET",
|
||||
headers: getHeaders()
|
||||
};
|
||||
return internalRequest(url, options);
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import { get } from "../../api/api";
|
||||
import { get } from "../../api/axiosApi";
|
||||
const baseUrl = process.env.REVERSE_PROXY_API_URL + "/system";
|
||||
|
||||
const getSystemDateTime = () => get(`${baseUrl}/datetime`);
|
||||
|
|
Loading…
Reference in New Issue