As the title states, I am trying to retrieve data from my server after it has finished being processed. More specifically, I am trying to get the processed data to my front end.
Background: A document is uploaded to google cloud, data is extracted from the document and stored in firestore, and then that extracted data is then sent back to the client. I have an API route that is able to receive that data sent by the server, however I’m having trouble getting that data then sent from the API route to the front end. I have tried server side events, polling, etc., but I can’t seem to find any luck with anything. Any advice or assistance is appreciated. Below is the API route I have attempted to use to get the data sent to the front end.
let data = null
export default async function handler(req, res) {
if (method === 'POST') {
try {
const data = req.body.data
console.log(data)
return res.status(200).json({ success: true })
} catch (error) {
console.error(`Error trying to receive data from workflow: ${error}`)
return res.status(400).json({ error: error })
}
}
if (method === 'GET') {
try {
return res.status(200).json({ data })
} catch (error) {
console.error(`Error trying to send data from workflow: ${error}`)
return res.status(500).json({ error: error })
}
}
}