1

hey so im using incremental static regeneration(ISR) in next js. im first saving a note to db through an api

    const sendData = async (formData: FormDataType) => {
 try {
 const response = await fetch('someapi/savenote', {
 method: 'POST',
 headers: {
 'Content-Type': 'application/json'
                    },
 body: JSON.stringify(formData)
                });

 const data = await response.json()

 if (data.status === 200) {
 const res = await fetch(`/api/fetchrecentnotes?category=${formData.category}`)
 const data2 = await res.json()
 return
                } 
            } catch (error) {
 console.error('Error saving note:', error);
            }
        }
    }

there i am calling the api fetch(/api/fetchrecentnotes?category=${formData.category}) to revalidate the path the api/fetchrecentnotes is

import { NextApiRequest, NextApiResponse } from 'next';

export default async function fetchRecentNotes(
  req: NextApiRequest,
  res: NextApiResponse
) {
  try {
    const category = req.query.category || "";
    await res.revalidate(`/${category}`)
    await res.revalidate('/')
    return res.status(200).json({ message: 'page revalidated' });
  } catch (error) {
    return res.status(500).json({ error });
  }
}

it is working fine in localhost after build. but it is not working in netlify hosted version. what is the solution?/ anybody please helpppp

0 Answers0