#How to avoid server side caching?

5 messages · Page 1 of 1 (latest)

bronze marlin
#

Hello! I am facing an issue in production, In development, my code works fine on some trigger, the request is sent to the server and then it brings back the desired data. However, in production, data once loaded, even on API request does not return the desired data. It is doing some sort of server caching. How to handle this. Please tell me I am new to NextJs.

type AllUsersResponse = {
  success: boolean
  users: User[]
}
export async function getAllUsers() {
  try {
    const {data: {users}} = await axios.get<AllUsersResponse>("/api/users")
    return users
  } catch (error: any) {
    console.error({ error: error.message })
  }
}

Following is the API code in app/api/users

import { connect } from "@/dbConfig/dbConfig"
import members from "@/models/member"
import { NextRequest, NextResponse } from "next/server"

connect()

export async function GET() {
  try {
    const users: any = await members.find({role: "USER"})
    return NextResponse.json({users, success: true}, {status: 200})
  } catch (error: any) {
    return NextResponse.json({ error: error.message }, { status: 500 })
  }
}
severe jackalBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

      🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in <id:customize>

      ✅ You can mark a message as the answer for your post with `Right click -> Apps -> Mark Solution`
      (if you don't see the option, try refreshing Discord with Ctrl + R)
polar salmon
#

Sorry headers doesn't provide a way to set headers, which is kinda stupid.
https://stackoverflow.com/questions/61812597/how-to-set-custom-http-response-headers-in-next-js-without-using-a-custom-server
Looks like you can do it with context.res?