Next.js Discord

Discord Forum

You're importing a component that needs next/headers. That only works in a Server Component which...

Unanswered
Black-tailed Gnatcatcher posted this in #help-forum
Open in Discord
Black-tailed GnatcatcherOP
Context:
Using nextjs app router + NestJS backend and want to fetch to my server components WITHOUT using route handlers because I realised they are useless for that use case.

Problem:
I need my fetch calls to have two specific headers "x-real-ip" & "x-forwarded-for", to handle my rate limiting. However as title says I get an error due to using headers outside of APP router. Please see example for example in code, my problem is I want to fetch in a different file than my server components to make my code easier to read as fetches get more.

1 Reply