Files
encoach_landingpage/src/cms/index.ts
2024-04-08 18:47:32 +01:00

25 lines
622 B
TypeScript

import axios from "axios";
interface StrapiResponse<T> {
data: {
id: number;
attributes: {
createdAt: Date;
updatedAt: Date;
publishedAt: Date;
locale: "en" | "ar";
} & T;
};
meta: object;
}
export async function getData<T>(page: string, locale: "ar" | "en"): Promise<T> {
const request = await axios.get<StrapiResponse<T>>(`${process.env.STRAPI_URL}/api/${page}/?populate=deep&locale=${locale}`, {
headers: {Authorization: `Bearer ${process.env.STRAPI_TOKEN}`},
});
console.log('GetDAta', page, JSON.stringify(request.data.data.attributes, null, 2));
return request.data.data.attributes;
}