Deployment Issue: Next.js, Astra DB with Cassandra, Successful Build but API Requests Failing vercel
Answered
Cuban Crocodile posted this in #help-forum
Cuban CrocodileOP
Hi team, I've encountered an issue with my project built using Next.js, Astra DB with Cassandra driver. Locally and in development, everything runs smoothly, and npm run build works perfectly. However, upon deployment on Vercel, the build is successful, but API requests (both GET and POST) are failing. I've shared the project on GitHub here. Below, I'll include screenshots to provide more context. Any insights or assistance would be greatly appreciated.
Answered by Ray
try this
secureConnectBundle: path.join(process.cwd(), "secure-connect.zip"),21 Replies
Cuban CrocodileOP
[GET] /api/todos status=500
[POST] /api/todos status=500
[POST] /api/todos status=500
Transvaal lion
Are you sending the requests to the deployed URL?
@Cuban Crocodile [GET] /api/todos status=500
[POST] /api/todos status=500
no error message?
try to log the error in a try/catch block on
try to log the error in a try/catch block on
/api/todosCuban CrocodileOP
here is my code, i did use try catch:
export async function GET (req: Request) {
try {
const query =
const data = (await cassandraDb.execute(query, [], { prepare: true })).rows.map((row ) => ({
id: row.todo_id?.toString(),
title: row.todo,
userId: row.user_id
}))
return NextResponse.json(data)
} catch (error) {
console.log('TODO_ROUTE_ERROR', error);
return new NextResponse('Something went wrong', { status: 500 })
}
};
// ADDING DATA
export async function POST (req: Request) {
try {
const { userId } = auth()
const values = await req.json();
const todoId = crypto.randomUUID();
const validatedFields = formSchema.safeParse(values);
if(!validatedFields.success) {
return new NextResponse('Invalid fields!', { status: 400 })
};
const { todo } = validatedFields.data;
const query =
await cassandraDb.execute(query, [todoId, todo, userId], { prepare: true });
return NextResponse.json({ success: todo })
} catch (error) {
console.log('TODO_ROUTE_ERROR', error);
return new NextResponse('Something went wrong', { status: 500 })
}
}
export async function GET (req: Request) {
try {
const query =
SELECT * FROM todos;const data = (await cassandraDb.execute(query, [], { prepare: true })).rows.map((row ) => ({
id: row.todo_id?.toString(),
title: row.todo,
userId: row.user_id
}))
return NextResponse.json(data)
} catch (error) {
console.log('TODO_ROUTE_ERROR', error);
return new NextResponse('Something went wrong', { status: 500 })
}
};
// ADDING DATA
export async function POST (req: Request) {
try {
const { userId } = auth()
const values = await req.json();
const todoId = crypto.randomUUID();
const validatedFields = formSchema.safeParse(values);
if(!validatedFields.success) {
return new NextResponse('Invalid fields!', { status: 400 })
};
const { todo } = validatedFields.data;
const query =
INSERT INTO todos (todo_id, todo, user_id) VALUES (?, ?, ?);await cassandraDb.execute(query, [todoId, todo, userId], { prepare: true });
return NextResponse.json({ success: todo })
} catch (error) {
console.log('TODO_ROUTE_ERROR', error);
return new NextResponse('Something went wrong', { status: 500 })
}
}
@Transvaal lion Are you sending the requests to the deployed URL?
Cuban CrocodileOP
yes
@Cuban Crocodile yes
check the environment variables on vercel
@Ray check the environment variables on vercel
Cuban CrocodileOP
see i already have the environmental variables
@Cuban Crocodile see i already have the environmental variables
do you have Restrict Public Access enabled on astra?
@Ray do you have Restrict Public Access enabled on astra?
Cuban CrocodileOP
no am not using that : also i tried using server actions and i got the same errors too, see my screenshots below:
I think vercel is not recognizing secure-connect.zip, what do i do
what is secure-connect.zip?
could you show the code on where you use it
@Ray what is secure-connect.zip?
Cuban CrocodileOP
here is the file, amd am using it in cassandra.ts,
here is my project in github: https://github.com/yaninyzwitty/cassandra-next-14
and my server actions one: https://github.com/yaninyzwitty/cassandra-next-14-server-actions
@Cuban Crocodile here is the file, amd am using it in cassandra.ts,
try
cloud: {
secureConnectBundle: process.cwd() + '/secure-connect.zip'
}Cuban CrocodileOP
These are the errors that i get on the browser and logs panel in vercel:
@Cuban Crocodile These are the errors that i get on the browser and logs panel in vercel:
try this
secureConnectBundle: path.join(process.cwd(), "secure-connect.zip"),Answer
Cuban CrocodileOP
Hi ray, i want to express my sincere gratitude for helping me identify and fix the bug , Am very thankful that it truly works, thanks once again for offering your time to give me that help. ðŸ™ðŸ¼ðŸ™ðŸ¼