import fsPromises from 'fs/promises'
import path from 'path'
import { Service, ServiceStatus } from '../../interfaces/Services';

export default async function ServicesAPI(req: any, res: any) {
  try {
    const filePath = path.join(process.cwd(), '/public/pages.json')
    const data = await fsPromises.readFile(filePath)
      .then((file) => JSON.parse(file.toString()));
    data.services.forEach((service: Service) => {
        service.status = ServiceStatus.loading;
      });

    res.status(200).json(data.services);
  }
  catch (error) {
    console.log(error);
    res.status(500).json({ error: 'Error reading data' });
  }
}

