N
Nuxt4mo ago
BlueStone

use SSR with backend server?

Im new to SSR stuff. in the past im using vite config for development and nginx for the production, so the backend api (in another language) is in the same domain as frontend. I want the SSR to fetch data from the backend to generate html, and I have read the "data fetching" section in the docs and seems it is about backend in nitro server. someone also mentions https://nuxt.com/docs/guide/directory-structure/components#standalone-server-components. what should i do?
Nuxt
components/ · Nuxt Directory Structure
The components/ directory is where you put all your Vue components.
5 Replies
BlueStone
BlueStoneOP4mo ago
Also, can i only render it on server side, so on the client side i don't have to request the backed api?
joe_black_unlucky
If you do your data requests with Pinia or asyncData, then your server will fetch the data and render in SSR and attach the state to the returned html to the client. Hydration will still occur on the client side, but should get the rendered page.
BlueStone
BlueStoneOP4mo ago
thanks so much, how to specify type on $fetch I found it out
BlueStone
BlueStoneOP4mo ago
@joe_black_unluckyhi, a few questions here. as the doc said, im using useFetch to fetch data from the server. I configured vite proxy and it is ignored, so I have to specify full url such as localhost:8080/api/xxx, and if I refresh the data on clients I think that will be broken. what should i do?
Nuxt
useFetch · Nuxt Composables
Fetch data from an API endpoint with an SSR-friendly composable.
BlueStone
BlueStoneOP4mo ago
I want to set the api url to /api/xxxxx so I can use nginx to reverse proxy on servers, but this causes SSR and dev failure solved
Want results from more Discord servers?
Add your server