0

I'm hosting a FastAPI backend server like this Vercel Template: https://vercel.com/templates/next.js/nextjs-fastapi-starter. I am trying to perform a fetch call in a Server Component using await fetch(${process.env.NEXT_PUBLIC_URL}/api/**`), where NEXT_PUBLIC_URL is configured to be the base url of the app (followed this forum: https://github.com/vercel/next.js/discussions/16429).

I am able to manually fetch the data when I put it in Google's search bar, but the fetch call fails and returns the HTML for 404 page not found. My theory is that because the call is prefetched on the server, it is not able to hit the Vercel Serverless FastAPI backend?

I have tried using it in a Client component and that works without the environment variable, since the client knows the base url. It just doesn't work in a Server Component.

Is there a better way to be able to make API calls to a Vercel Serverless FastAPI backend? Thanks!

0

Browse other questions tagged or ask your own question.