NextJs 14 api routes showing 404 in production but works with localhost

I built a nextjs 14 application using its api route functionality to build a backend service that send email to whoever register on the platform. Everything works fine on local but if the deployed version to netlify isn’t working.

For examples I created a GET route /api/sendEmail/routes.ts to return just a message and if I try hitting this path:
http://localhost:3000/api/sendEmail (Everything works as expected)
But https://fo-foundation.netlify.app/api/sendEmail (is returning 404 error for the endpoint).

Please, what could be the cause and the likely solution to the issue.

Below is the project folder structure:

Below is the netlify log for building:

Have you tried setting your publish directory to .next?

@lab1234 Have you added a api endpoint env variable? You need to specify the base url of site on production for the api. You can add the variable in Netlify, and put it in .env locally.

NEXT_PUBLIC_APP_API_ENDPOINT=http://localhost:8888

fetch( ${process.env.NEXT_PUBLIC_APP_API_ENDPOINT}/api/blah})

Thank you @hrishikesh
Actually I set the export to output in the next config file, which I later found out that its only building a client side codes for deployment.

So I commented that out and set publish folder to .next but the application is not coming up even after successful deployment. Opening the URL shows not found.

And before it was working only the API route was not found.

Hi @Graemec23 yes, I was using relative path so it automatically pick the root address.

Your deploys after the 23rd have all failed. In the deploy on the 23rd, you still had the config set to out, is my understanding. Did you try to fix the error being reported in your latest logs?

Oooh! I got tired when it didn’t work for different attempts. I will check and update you if it works fine now.

Thank you very much.

I am facing the same issue, if you find a way, please do share. It was all working fine. I deployed it was working then later when I checked again the API was unresponsive.

can you share the site you’re seeing this issue on?