25 lines
622 B
TypeScript
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;
|
|
|
|
}
|