Don't send undefined content type in frontend
This commit is contained in:
parent
e2dd9d9e6e
commit
fb3705690d
@ -3,13 +3,16 @@ import { address } from "./constants.js";
|
||||
export async function request(method, path, body = null) {
|
||||
const token = document.cookie.match(/\bauth-token=([^;\s]+)/);
|
||||
|
||||
const headers = {};
|
||||
if (body)
|
||||
headers["Content-Type"] = "application/json";
|
||||
if (token?.length > 1)
|
||||
headers["Authorization"] = `Bearer ${token[1]}`;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
fetch(address + path, {
|
||||
method,
|
||||
headers: {
|
||||
"Content-Type": body ? "application/json" : undefined,
|
||||
"Authorization": token?.length > 1 ? `Bearer ${token[1]}` : undefined,
|
||||
},
|
||||
headers,
|
||||
body: body ? JSON.stringify(body) : undefined,
|
||||
})
|
||||
.then(async response => {
|
||||
|
Loading…
Reference in New Issue
Block a user