import axios from 'axios';
import { NextApiRequest, NextApiResponse } from 'next';
import { API_URL } from '../constants/constants';

export const fetchPageData = async (slug: string): Promise<any> => {
  const res = await axios.get(`${API_URL}/pages?slug=${slug}`);
  const data = await res.data;
  return data[0];
};

export const fetchCaseData =async (uid:string) => {
  const res = await axios.get(`${API_URL}/case-studies/${uid}`);
  const data = await res.data
  return data[0];
  
}

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {
  const { slug } = req.query;
  const data = await fetchPageData(slug as string);

  res.status(200).json({ data });
}
