I can see the issue with your cron job route handler. The problem is that you’re not returning the data from your fetch request, and there’s a syntax error in your Authorization header check
import { NextResponse } from "next/server"
export async function GET(req: Request) {
const authHeader = req.headers.get("Authorization")
// Fix the template literal syntax
if (authHeader !== `Bearer ${process.env.CRON_SECRET}`) {
console.log("Unauthorized access attempt")
return new NextResponse("Unauthorized", { status: 401 })
}
try {
console.log("Cron job started")
const response = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_SERVER}/items/0/2/all`, {
method: "GET",
})
// Get the actual data from the response
const data = await response.json()
console.log("Cron job completed successfully", data)
return NextResponse.json({
message: "Cron job executed successfully",
data: data, // Include the fetched data in the response
})
} catch (error) {
console.error("Error triggering website:", error)
return new NextResponse("Failed to trigger external website", {
status: 500,
})
}
}