Prepared the website to work with the CMS
This commit is contained in:
23
src/cms/index.ts
Normal file
23
src/cms/index.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import axios from "axios";
|
||||
|
||||
interface StrapiResponse<T> {
|
||||
data: {
|
||||
id: number;
|
||||
attributes: {
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
publishedAt: Date;
|
||||
locale: "en" | "ar";
|
||||
} & T;
|
||||
};
|
||||
meta: object;
|
||||
}
|
||||
|
||||
type Result<T> = {data: StrapiResponse<T>; isError: boolean};
|
||||
|
||||
export async function getData<T>(page: string, locale: "ar" | "en"): Promise<Result<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}`},
|
||||
});
|
||||
return {data: request.data, isError: request.status !== 200};
|
||||
}
|
||||
Reference in New Issue
Block a user