mirror of
https://github.com/wowlikon/LiB.git
synced 2026-02-04 04:31:09 +00:00
Исправление mixed content
This commit is contained in:
@@ -53,7 +53,12 @@ const Utils = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const Api = {
|
const Api = {
|
||||||
|
getBaseUrl() {
|
||||||
|
return window.location.origin;
|
||||||
|
},
|
||||||
|
|
||||||
async request(endpoint, options = {}) {
|
async request(endpoint, options = {}) {
|
||||||
|
const fullUrl = this.getBaseUrl() + endpoint;
|
||||||
const token = localStorage.getItem("access_token");
|
const token = localStorage.getItem("access_token");
|
||||||
const headers = {
|
const headers = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -67,14 +72,14 @@ const Api = {
|
|||||||
const config = { ...options, headers };
|
const config = { ...options, headers };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(endpoint, config);
|
const response = await fetch(fullUrl, config);
|
||||||
|
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
const refreshed = await Auth.tryRefresh();
|
const refreshed = await Auth.tryRefresh();
|
||||||
if (refreshed) {
|
if (refreshed) {
|
||||||
headers["Authorization"] =
|
headers["Authorization"] =
|
||||||
`Bearer ${localStorage.getItem("access_token")}`;
|
`Bearer ${localStorage.getItem("access_token")}`;
|
||||||
const retryResponse = await fetch(endpoint, { ...options, headers });
|
const retryResponse = await fetch(fullUrl, { ...options, headers });
|
||||||
if (retryResponse.ok) {
|
if (retryResponse.ok) {
|
||||||
return retryResponse.json();
|
return retryResponse.json();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user