Retrieving data without using getServerSideProps and not exposing API keys

In my application I have a custom _app file which restricts using getServerSideProps but I need to retrive data from and external API without exposing keys, what is the best possible way to go about it?
12 Replies
Neto
Neto2y ago
use an api route
Yiaoma
Yiaoma2y ago
So this would be 2 calls to external source and my own server from frontend?
Neto
Neto2y ago
client -> next api -> external api -> next api (response) -> client (response) plus you can add caching and stuff
Yiaoma
Yiaoma2y ago
Thank you!
Neto
Neto2y ago
^^
rocawear
rocawear2y ago
Why not call external api on ssr or ssg straight
Lukem121
Lukem1212y ago
What kind of caching?
Neto
Neto2y ago
you can use something with redis to a more "vendor free" example or cache headers
Neto
Neto2y ago
youtube.com/@bholmesdev (@BHolmesDev)
With serverless on the rise, cache is king 💰 To speed up responses and cut down on your server biil, let's walk through Cache-Control headers that'll fine-tune how and where cache is stored! #WhiteboardTheWeb edition 59
Likes
1063
Retweets
145
Twitter
Yiaoma
Yiaoma2y ago
Arent those disabled when using custom app file?
rocawear
rocawear2y ago
Oh didnt know you use that
Yiaoma
Yiaoma2y ago
No problem haha, not using next13 yet :d
Want results from more Discord servers?
Add your server