map to new back

This commit is contained in:
kandrusyak
2023-07-25 02:11:01 +03:00
parent dcaa7b7995
commit 35ff1150e7
5 changed files with 120 additions and 12497 deletions

View File

@@ -1,5 +1,3 @@
import router from "@/router";
function prepareUrl(url) {
if (url.startsWith("http")) return url;
return `https://astra-dev.dopcore.com/api/${url}`;
@@ -15,8 +13,7 @@ function handleRequest(method, url, headers, attempts, body, type) {
})
.then((res) => {
if (res.status === 401) {
localStorage.removeItem("tokenAccess");
router.go("/login");
//router.go("/login");
} else if (res) return res.json();
})
.catch((err) => {
@@ -33,13 +30,12 @@ function handleRequest(method, url, headers, attempts, body, type) {
* @param {string} type - request type
*/
function request(method, url, headers = {}, body, type = "") {
let token = localStorage.getItem("tokenAccess");
let requestOptions = {};
if (method === "GET" || method === "DELETE") {
requestOptions = {
method: method,
credentials: "include",
headers: {
Authorization: `Bearer ${token}`,
...headers,
"Content-Type": "application/json",
Accept: "application/json",
@@ -54,21 +50,21 @@ function request(method, url, headers = {}, body, type = "") {
requestOptions = {
method: method,
headers: {
Authorization: `Bearer ${token}`,
Accept: "application/json",
...headers,
},
body: body,
credentials: "include",
};
} else
requestOptions = {
method: method,
headers: {
Authorization: `Bearer ${token}`,
Accept: "application/json",
"Content-Type": "application/json",
...headers,
},
credentials: "include",
body: JSON.stringify(body),
};
}