Don't send undefined content type in frontend

This commit is contained in:
Reimar 2025-03-31 11:03:38 +02:00
parent e2dd9d9e6e
commit fb3705690d
Signed by: Reimar
GPG Key ID: 93549FA07F0AE268

View File

@ -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 => {