import type { NextApiRequest, NextApiResponse } from 'next';

type ResponseData = {
  message: string;
};

export default async function GET(req: NextApiRequest, res: NextApiResponse<any>) {
  if (!req.headers['x-echo-url']) {
    return res.status(404).send('No URL provided');
  }

  const response = await fetch(`${req.headers['x-echo-url']}?action=discover`);

  const json = await response.json();

  const workflow = json.workflows.find((item) => item.workflowId === req.query.workflowId);
  res.json(workflow);
}
