Start fetchdata kql

This commit is contained in:
isUnknown 2024-07-10 18:43:46 +02:00
parent 3ed204123a
commit 90c998fa41
13 changed files with 109 additions and 34 deletions

46
src/stores/api.js Normal file
View file

@ -0,0 +1,46 @@
import { defineStore } from "pinia";
export const useApiStore = defineStore("counter", () => {
function fetchData() {
const api = "/api/query";
const username = import.meta.env.VITE_USERNAME;
const password = import.meta.env.VITE_PASSWORD;
const token = btoa(`${username}:${password}`);
const headers = {
Authorization: `Basic ${token}`,
};
const request = {
method: "post",
body: JSON.stringify({
query: `page('home')`,
select: {
testImages: {
query: "page.testImages.toFiles",
select: {
url: true,
},
},
blocks: {
query: "page.testBlocks.toBlocks",
},
},
}),
headers,
};
fetch(api, request)
.then((response) => response.json())
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
}
return { fetchData };
});