Method not allowed on built app, but works on dev...
Unanswered
Petit Bleu de Gascogne posted this in #help-forum
Petit Bleu de GascogneOP
This code, works on dev, but seems like when i build the app, I get a 405 error with Method not allowed...
I'm using nextjs 14.2.0.
I'm using nextjs 14.2.0.
const updateData = async (data: DataModel[]) => {
console.log("Updated Data:");
try {
const response = await axios.put("/dnd/api/updateData", {
data: data,
});
if (response.status === 200) {
console.log("Data updated successfully");
}
} catch (error) {
console.error("Error updating data: ", error);
}
};3 Replies
Petit Bleu de GascogneOP
I'm using the same endpoint for a get request too, and works fine....
GET http://localhost:3000/dnd/api/updateData: status 200
PUT http://localhost:3000/dnd/api/updateData: status 405, method not allowed....
GET http://localhost:3000/dnd/api/updateData: status 200
PUT http://localhost:3000/dnd/api/updateData: status 405, method not allowed....
export async function GET(request: NextRequest) {
try {
//get data code
return NextResponse.json({ data});
} catch (error) {
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
}
}
// Update the sections with new data
export async function PUT(request: NextRequest) {
try {
const { data } = await request.json();
//do something with data
return NextResponse.json({
message: "Data updated successfully",
});
} catch (error) {
return NextResponse.json(
{ error: "Internal server error" },
{ status: 500 }
);
}
}Well, looks like there is a bug from 14.2.0. and 14.2.1. Downgraded to 14.1.4, and now works fine...