I asume you followed this tutorial ? Create a food ordering app with Strapi and Next.js (1)
As you said your frontend uses NEXT_PUBLIC_API_URL=http://localhost:1337 address for backend, this step was described in the Introduction chapter [1/7] and was configured ONLY for local development. On the last chapter of tutorial [7/7] you can notice that NEXT_PUBLIC_API_URL was changed to the Public URL(Heroku URL for backend), I think you skipped that part and left the variable untouched.