Hello, Netlify support.
I successfully deployed my app on Netlify but I keep getting an error Request failed with status code 502
when I try to make an API request to a function. I am using next: 15.3.3
. The app works fine locally.
Here’s the function:
import { headers } from "next/headers";
import { NextResponse, NextRequest } from "next/server";
import { verifyJWT } from "../../_actions/auth/jwt-verification";
import userModel from "@/models/userModel";
export const GET = async (_req: NextRequest) => {
try {
const requestHeaders = await headers();
const authorization_headers = requestHeaders.get("token");
if (!authorization_headers) {
return NextResponse.json({
success: false,
message: "Not Authorized. Please Login.",
});
}
const user_id = await verifyJWT(authorization_headers);
let user = await userModel.findById(user_id).lean();
if (!user) {
return NextResponse.json({ success: false, message: "User not found" });
}
if (!user.cartData) {
user.cartData = {};
}
return NextResponse.json({ success: true, user });
} catch (error) {
console.log(error);
return NextResponse.json({ success: false, message: error.message });
}
};
My initial assumption was that netlify doesn’t support next/headers
but from this post, I ruled that option out. Any kind of help resolving this will be highly appreciated.