47 lines
1,001 B
JavaScript
47 lines
1,001 B
JavaScript
|
|
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 };
|
||
|
|
});
|