Route workin in Dev and not Prod?

Hey guys I have a route defined (code below) that in dev works fine, I call it with PUT and it does just that fine. I am using latest NextJS 14 and am hosgting prod env in Vercel. In prod I get:
Request URL:
https://xxxxxx/api/defendants?id=13
Request Method:
PUT
Status Code:
405 Method Not Allowed
Remote Address:
xxxxxxx
Referrer Policy:
strict-origin-when-cross-origin
Request URL:
https://xxxxxx/api/defendants?id=13
Request Method:
PUT
Status Code:
405 Method Not Allowed
Remote Address:
xxxxxxx
Referrer Policy:
strict-origin-when-cross-origin
But the same call works perfectly fine in dev
Request URL:
http://localhost:3000/api/defendants?id=210
Request Method:
PUT
Status Code:
200 OK
Remote Address:
[::1]:3000
Referrer Policy:
strict-origin-when-cross-origin
Request URL:
http://localhost:3000/api/defendants?id=210
Request Method:
PUT
Status Code:
200 OK
Remote Address:
[::1]:3000
Referrer Policy:
strict-origin-when-cross-origin
// /api/defendants.js
import { NextRequest, NextResponse } from "next/server";
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

export async function GET() {
try {
const defendants = await prisma.defendant.findMany({
select: {
id: true,
companyName: true,
companyAddress: true,
ownerName: true,
ownerAddress: true,
ownerPhone: true,
ownerEmail: true,
},
});

return NextResponse.json({ defendants });
} catch (error) {
console.error("Error fetching defendants:", error);
return NextResponse.json(
{ error: "Internal Server Error" },
{ status: 500 },
);
} finally {
await prisma.$disconnect();
}
}

export async function PUT(request: NextRequest) {
try {
const data = await request.json();
const updatedDefendant = await prisma.defendant.update({
where: { id: data.id },
data: {
companyName: data.companyName,
companyAddress: data.companyAddress,
ownerName: data.ownerName,
ownerAddress: data.ownerAddress,
ownerPhone: data.ownerPhone,
ownerEmail: data.ownerEmail,
},
});

return NextResponse.json({ defendant: updatedDefendant });
} catch (error) {
console.error("Error updating defendant:", error);
return NextResponse.json(
{ error: "Internal Server Error" },
{ status: 500 },
);
} finally {
await prisma.$disconnect();
}
}
// /api/defendants.js
import { NextRequest, NextResponse } from "next/server";
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

export async function GET() {
try {
const defendants = await prisma.defendant.findMany({
select: {
id: true,
companyName: true,
companyAddress: true,
ownerName: true,
ownerAddress: true,
ownerPhone: true,
ownerEmail: true,
},
});

return NextResponse.json({ defendants });
} catch (error) {
console.error("Error fetching defendants:", error);
return NextResponse.json(
{ error: "Internal Server Error" },
{ status: 500 },
);
} finally {
await prisma.$disconnect();
}
}

export async function PUT(request: NextRequest) {
try {
const data = await request.json();
const updatedDefendant = await prisma.defendant.update({
where: { id: data.id },
data: {
companyName: data.companyName,
companyAddress: data.companyAddress,
ownerName: data.ownerName,
ownerAddress: data.ownerAddress,
ownerPhone: data.ownerPhone,
ownerEmail: data.ownerEmail,
},
});

return NextResponse.json({ defendant: updatedDefendant });
} catch (error) {
console.error("Error updating defendant:", error);
return NextResponse.json(
{ error: "Internal Server Error" },
{ status: 500 },
);
} finally {
await prisma.$disconnect();
}
}
3 Replies
oz
ozOP6mo ago
Bump :sobskull:
Luke
Luke6mo ago
Out of curiosity, are you using any auth library or are you using any Next.js middleware?
oz
ozOP6mo ago
Both actually I solved this by just doing route/[id] Still dont know why this happened
Want results from more Discord servers?
Add your server