#how to get the domain name that vercel uses when deploying for setting up an env variable
24 messages · Page 1 of 1 (latest)
🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord
🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize
✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)
I think it can help you they had the same problem as you : https://github.com/vercel/next.js/discussions/16429#discussioncomment-1302156
Hi, I am trying to setup SEO for site. It will need a full URL like : https://mysite.com/product/a-product But how can we get value mysite.com? I am use env file, it work but If we have 2 domains p...
From what he said you should have the url like thisjs NEXT_PUBLIC_URL=https://$NEXT_PUBLIC_VERCEL_URL
If you think you "need the domain" for fetching you're own API you're doing something wrong, because you do not. fetch('/api/foo') will automatically use the domain as the base URL wherever you deploy.
in some place of my code the fetch method is unable to create the correct url. it throws an invalid url error if the url is not complete :/
Then you are doing something wrong. Are you attempting to fetch your own server from within server-side code? If so, you shouldn't do that either.
It makes no sense to order via the drive-through while you're already sitting inside of McDonald's.
i don't like server action
Just call the functions, that you endpoint would use, directly instead of fetching your own endpoint from server-side code.
or calling directly the function
But it's wrong and not idiomatic. Additionally, you're introducing another unnecessary roundtrip. Please read this, and in particular the final sections: https://nextjs-faq.com/fetch-api-in-rsc
interesting, who is the author of this blog
It's a collaborative effort of a few experienced community members.
really cool ill pin it thank you. Using api routes made my code more organized everything in one place, this is what I liked from it. Ill try this approach inshAllah.
also what i liked with fetch is the caching control i had with it
Public API routes are only for two use-cases: purely client-side fetching and 3rd parties accessing your public API. Everything else can be done directly using server components (which is the the whole point of them) and server actions for mutations.
since now i don't use fetch, i will have to use the unstable_cache if i am correct
Yeah, it's more granular in case you require caching and will be replaced with something even more convenient in the future.
Yes, it has probably been one of the most stable things of the app router. You just need to read thoroughly how it's used because there are some minor details that are easy to mistake.