I’m a new practitioner of next.js and am currently working through a project that connects openAI to pdfs. However, while working through the project I have come a cross a problem.
I’ve created an api module named create-chat, but when I try to access it at localhost:3000/api/create-chat, I get error 404 back, despite the URL being correct and the module obviously existing. So I am unsure of where my routing issue lies.
This is my create-chat/route.ts file:
import { db } from "@/lib/db";
import { chats } from "@/lib/db/schema";
import { loadS3IntoPinecone } from "@/lib/pinecone";
import { getS3Url } from "@/lib/s3";
import { auth } from "@clerk/nextjs";
import { NextResponse } from "next/server";
// /api/create-chat
export async function POST(req: Request) {
const { userId } = await auth();
if (!userId) {
return NextResponse.json({ error: "unauthorized" }, { status: 401 });
}
try {
const body = await req.json();
const { file_key, file_name } = body;
console.log(file_key, file_name);
await loadS3IntoPinecone(file_key);
const chat_id = await db
.insert(chats)
.values({
fileKey: file_key,
pdfName: file_name,
pdfUrl: getS3Url(file_key),
userId,
})
.returning({
insertedId: chats.id,
});
return NextResponse.json(
{
chat_id: chat_id[0].insertedId,
},
{ status: 200 }
);
} catch (error) {
console.error(error);
return NextResponse.json(
{ error: "internal server error" },
{ status: 500 }
);
}
}
I’ve tried creating a custom server.js file. I’ve verified that my path is correct. I’ve set up my Middleware config page as instructed to on Clerk’s website… I’m at a loss at how to debug this error.
1