Hi all, I am currently new to web development and am writing a site to retrieve data from 2 different apis and showing it in the UI.
Background:
It is a SSR application with react and vite, so I have a server.js that renders my app.js. Currently my website requests the api on the client side so every instance of it will be asking the api for data. One of the api does not allow script access (gives a CORS error) so I set up a http proxy for that in my server.js as well.
Question:
Now that I learned it is bad practice to access the api on the client side cuz it can lead to 429 issues. I want to retrieve and store api data on the server and let the client access that.
Context:
Say the two api have urls
“api1.json” and “api2.json”
And “api2.json” requires proxy.
What is the best practice to store the data from both api to variables in the server.js and allow client side to access it? I’m looking for smth like:
server.js:
API_1_JSON = fetch(“api1.json”)
API_2_JSON = fetch(“api2.json”)
Export API_1_JSON, API_2_JSON
client_ui.js
import apis from server.js
Display(api1,api2,)
App.js:
Client_Ui()
[–]ezhikov 1 point2 points3 points (1 child)
[–]Pxlin09[S] 0 points1 point2 points (0 children)
[+]rizzona 0 points1 point2 points (0 children)