Fix CORS preflight hang: GET токен через ?_t query (без Authorization)
This commit is contained in:
parent
9a9d8a7761
commit
4af525c7b8
@ -43,9 +43,16 @@ const Store = {
|
||||
async function api(path, opts = {}, _retry = 0) {
|
||||
// rebuild opts on every retry (body may be already stringified)
|
||||
const o = { ...opts, headers: { ...(opts.headers || {}) } };
|
||||
if (Store.access && !o.headers.Authorization) {
|
||||
// для GET — передаём токен через query (избегаем CORS preflight на Authorization)
|
||||
// для POST/PUT/DELETE — оставляем в headers
|
||||
const isGet = !o.method || o.method === 'GET' || o.method === 'HEAD';
|
||||
if (Store.access && !o.headers.Authorization && !isGet) {
|
||||
o.headers.Authorization = `Bearer ${Store.access}`;
|
||||
}
|
||||
if (Store.access && isGet) {
|
||||
const sep = path.includes('?') ? '&' : '?';
|
||||
path = path + sep + '_t=' + encodeURIComponent(Store.access);
|
||||
}
|
||||
if (o.body && typeof o.body === 'object' && !(o.body instanceof FormData)) {
|
||||
o.headers['Content-Type'] = 'application/json';
|
||||
o.body = JSON.stringify(o.body);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user