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 })
}
}