Deploy fetching own route handler.
Unanswered
Mini Satin posted this in #help-forum
Mini SatinOP
Hi eveyrone,
How am I supposed to deploy an app that is deployed for the first time which is fetching his own API route in the page.tsx?
I am trying to deploy an app using Next.js and the route handlers, I have one GET route in app/api/products that returns a list of products. In dev mode in my page.tsx I'm fetching the data like that fetch('http://localhost:3000/api/products') since fetch('/api/products') is not working like the old way ( back in Next 12 ) . Everything is working as expected in dev mode. But once I deploy on Vercel, it fails. The page.tsx can't be compiled since the route /api/products doesn't exist during build time. I tried preshoting the URL, like if my domain name is example.com , I just replaced by fetch('https://example.com/api/products') and tried deploying.
Still fails, which means an api route should already exist somewhere before building the page... then how am I supposed to do ? Create another app with only the back (not fetching own route to avoid build issue ) then deploy my first app fetching the second app's API route , once done redeploy changing the fetch URL of my app to my own API ?
How am I supposed to deploy an app that is deployed for the first time which is fetching his own API route in the page.tsx?
I am trying to deploy an app using Next.js and the route handlers, I have one GET route in app/api/products that returns a list of products. In dev mode in my page.tsx I'm fetching the data like that fetch('http://localhost:3000/api/products') since fetch('/api/products') is not working like the old way ( back in Next 12 ) . Everything is working as expected in dev mode. But once I deploy on Vercel, it fails. The page.tsx can't be compiled since the route /api/products doesn't exist during build time. I tried preshoting the URL, like if my domain name is example.com , I just replaced by fetch('https://example.com/api/products') and tried deploying.
Still fails, which means an api route should already exist somewhere before building the page... then how am I supposed to do ? Create another app with only the back (not fetching own route to avoid build issue ) then deploy my first app fetching the second app's API route , once done redeploy changing the fetch URL of my app to my own API ?