import httpClient from "@/api/http-client"; import {Payload} from "@/types/generated-strapi-interfaces/common/Payload"; const STRAPI_URL = process.env.STRAPI_URL; class StrapiClient{ constructor(private strapiUrl: string = "http://localhost:1337") { } public getImageUrl(imagePath: string){ if ( !imagePath ){ return "dummy.png" } return '/image/'+ imagePath; } public async httpGet(path: string){ console.info("httpGet", path); return await httpClient.httpGet(this.strapiUrl + path); } public async httpGetJson(url: string): Promise>{ const response = await this.httpGet(url); return await response.json(); } public async findContentType(contentType: string,options?: FindContentOptions): Promise>{ const searchParams = new URLSearchParams(); if ( options?.populateAll ){ searchParams.append("populate","*"); } if (options?.localeAll){ searchParams.append("_locale","all"); } const response = await this.httpGet("/api/"+contentType+"?"+searchParams.toString()); return await response.json(); } } export interface FindContentOptions{ populateAll?: boolean; localeAll?: boolean; } const client = new StrapiClient(STRAPI_URL); export default client;