I'm trying to call my NextJS API: If I try to write
const res = await fetch("/api/commands");
const res = await fetch("/api/commands");
I get the error 'failed to parse URL' despite the API endpoint clearly existing and being accessible via
http://localhost:3000/api/commands
http://localhost:3000/api/commands
.
To get around this, I declared a base URL variable so I could at least make it work in localhost and hopefully Vercel too (according to Vercel's docs they have a VERCEL_URL that points to the deployment's URL):