nuxt / framework

Old repo of Nuxt 3 framework, now on nuxt/nuxt

Home Page:https://nuxt.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Server directory documentation about SSR requests and performance with nuxt

mkierdev opened this issue · comments

Describe the feature

Hi,
I believe that Nitro and server-side code in nuxt 3 is a gamechanger, however I feel like server directory lacks documentation.
What I am trying to acknowledge is how much of performance cost (if any) it can incur in nuxt application.
As far as I understand, we can use server/api directory to reqister server-side code. In this way, we can use secure tokens that won't ever be exposed to client.

So basically, we created simple functions in server/api. Their sole job is to fetch data from an endpoint that is outside nuxt scope. One function per one request. Current workflow:

// products.ts file:
const res = fetch('...myapi...')
return res.json()

// page / component.vue
const products = await useFetch('/server/api/products.ts')

What is the performance costs vs traditional approach where we would directly call an API endpoint from nuxt application?
Can we safely use server/api in high-traffic (e-commerce) large application?
How high is the performance overhead? Are there any limitations that we should know about?
I tried to measure it somehow by myself but I don't have any idea how to do it properly.

If server is not a way to go, is there any alternative to make secure calls? Process.server would not work, because it can only be respected on initial page load (after that client takes over).

Additional information

  • Would you be willing to help implement this feature?
  • Could this feature be implemented as a module?

Final checks