#How to use custom routes without /api path "nextjs"

11 messages · Page 1 of 1 (latest)

blissful depotBOT
#

🔎 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)

trail fossil
#

You wanna call your API within your next js app or within a server??

brisk flint
#

Are you sending this POST request from the client?

#

Yeah, in this case you're going to need to make an API route to handle this, the request to your back-end needs to come from a server not a client, clients are not trust-worthy hence the CORS error, I had a similar issue when I was trying to POST data from the client to a google form, the request needed to come from a server in order for my error to subside.

#

Are you talking about the compute time of the functions on the server? Are you worried about the functions consuming more of that?

#

Yeah it's possible that it's do the nature of how Serverless functions work, they start cold so it takes them a while to get up and running, but, once they are warm the time decreases significantly, IMO, it's better for this to be done on the server than eating the client bandwidth, people with slower internet connections will suffer greatly.

I'd suggest reviewing the limits of the hosting service you're using and gaging the execution units/time limits and if you're receiving so much traffic or consuming so much bandwidth that you're worried you'll hit the limit, I don't know if anything can be done besides upgrading, this type of action should be performed on the server for the most optimal performance afaik. Hope this helped.

#

Yeah it's likely Server Actions will change the way we think about/perform these types of interactions.

vast dawn
#

you could also simply use a reverse proxy by using rewrites

#

that's the solution to CORS-related issues if you don't want to update CORS or you don't want to let the world know your backend domain

surreal oyster
#

if you want to call it from the browser to ur backend api, what's the issue with a normal fetch()? and yea allow the domains from which u want to hit in ur BE.