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
Liam
Liam13mo ago
It looks like all vercel deployments should have a VERCEL_URL variable that has the URL of that deployment 👍
WO
WO13mo ago
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
Want results from more Discord servers?
Add your server
More Posts
Moving Prisma Schema To Its Own Package in a TurborepoHello! I would like to move my prisma schema into its own package within a monorepo using turborepotRPC losing types on t3-turboI'm trying the t3 turbo repo, trpc loses type defs out of nowhere on nextjs, types work fine on expoShadcn fonts not workingHi! So I'm using shadcn for as my component library. I'm using the Dialog component together with nereact query persistQueryClient: store each queryKey/queryHash in its own IDB k-v rowI'm currently using react query to persist some queries to indexedDB (a lot of queries, so i can't uTypescript error for "property does not exist', when it clearly does.I have some objects (named `program`' in code) in an array which I am iterating through, and readingContext in App dirI just wanted to understand , if I have global context providers that I need to use in all componentDiscord OAUTH not working, I've tried almost everythingWhen I try to sign in with discord it gives me the "Try signing in with a different account" error. What is the best way to push data from external sources into my db?I want to import data from external sources into my app. I think it would be more efficient to accespersist user vertical scroll during navigation between pages NEXT 13 App Diri wanna learn how to keep the user where he was during navigation between pages like, open blog postReading public folder on prodHey y'all! So I have a folder of images residing in `/public`, that I read from a trpc procedure, an