// /pages/api/getGhostPosts.js
export default async function handler(req, res) {
    const { NEXT_PUBLIC_GHOST_API_URL, NEXT_PUBLIC_GHOST_CONTENT_API_KEY } = process.env;
  
    // Construct the API URL with the Ghost API key
    const url = `${NEXT_PUBLIC_GHOST_API_URL}/ghost/api/v3/content/posts/?key=${NEXT_PUBLIC_GHOST_CONTENT_API_KEY}`;
  
    try {
      const response = await fetch(url);
      const data = await response.json();
  
      // Send the posts data as JSON to the client
      res.status(200).json(data.posts);
    } catch (error) {
      res.status(500).json({ error: 'Error fetching posts from Ghost CMS' });
    }
  }