I have developed a Node.js/Express application that utilizes an API based on inputs and a button click from the front end. The API endpoints were functioning correctly on my localhost environment but are currently failing to work after deploying the application to Vercel.
Issue Description:
Local Environment: The application works flawlessly when running on localhost. API calls to endpoints such as /openai/user-research and others respond correctly with the expected data.
Vercel Deployment: After deploying the application to Vercel, I am encountering issues where API calls return a 405 Method Not Allowed error. This error can be seen in the error message bar at the bottom of the page on the front end, indicating that the requests are not being processed as intended.
Expected Behavior: A successful Open ai API call should return a response containing relevant data.
Request for Assistance:
I would appreciate any guidance on troubleshooting the issue with API calls in the Vercel deployment and steps to resolve it, as it is critical for the functionality of my application.
my app.js is in the root folder - except below:
app.post('/openai/user-research', generateUserResearch);
my index.js file is in the public folder - excerpt below:
fetch('/openai/user-research', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
customerSegment,
valueProposition,
}),
i also added this vercel.json to the root folder:
{
"rewrites": [
{"source": "/(.*)", "destination": "/"}
]
}
Thank you!