Prepared the website to work with the CMS

This commit is contained in:
Tiago Ribeiro
2024-03-18 10:21:28 +00:00
parent 3c5629f83a
commit 91ee920b42
14 changed files with 233 additions and 1 deletions

23
src/cms/index.ts Normal file
View 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};
}