Caching a request with headers
Unanswered
Indian mackerel posted this in #help-forum
Indian mackerelOP
i have a fetch request that i need to protect, i am currently using
basically i need to have a route in my express backend accessible only by the nextjs server, i also want to be able to cache the request
The reason i need to cache the request:
I need this request to display information in my page, this information doesnt need to change frequently, so i need to kinda SSG-like render the page (i cannot use SSG because my navbar has information based on
this is the request code
Authorization
header to do that but like this i cannot cache the request, how do i work around this? is there a way to "force-cache"
a request even if it uses headers? if not possible why this limitation?basically i need to have a route in my express backend accessible only by the nextjs server, i also want to be able to cache the request
The reason i need to cache the request:
I need this request to display information in my page, this information doesnt need to change frequently, so i need to kinda SSG-like render the page (i cannot use SSG because my navbar has information based on
getServerSession
which is a server function) and i dont want to use useSession
neither to keep as much as i can server-sidethis is the request code
export async function getGroups() {
const groupsData = await (
await fetch(process.env.NEXT_PUBLIC_SERVER_URL + "/groups", {
method: "GET",
headers: {
Authorization: process.env.SUPERSECRET,
},
cache: "force-cache",
next: {
tags: ["groups"],
},
})
).json();
return groupsData;
}
4 Replies
European sprat
why did you create a new post when you already have an identical one?
if you have more info, add it to the other post
Indian mackerelOP
i read on the rules i could "bump" a post, i thought that this is what it meant
European sprat
you add more info to the old post to bump it