How do I setup a base api url for the preview environment when deploying to Vercel?
New to Next and working with API routes. My API routes are working locally when I use http://localhost:3000/api as the base URL but how would I create a base url for the preview environment since the url is dynamic?
2 Replies
It looks like all vercel deployments should have a
VERCEL_URL
variable that has the URL of that deployment 👍Thanks trying this now
Seems like it does get the preview deployment URL and I appended the api route to it but getting an error for invalid url
let API_URL;
if (process.env.NODE_ENV === "development") {
API_URL = "http://localhost:3000/api";
} else {
API_URL =
${process.env.VERCEL_URL}/api;
}
export const BASE_API_URL = API_URL;
Not sure if this is the right way to go about it. In the deployment logs it shows that its attempting to hit the preview URL with my API route appended but says its an invalid url