Fix: Resolve 500 error in AI solver due to Neon/Drizzle initialization#288
Fix: Resolve 500 error in AI solver due to Neon/Drizzle initialization#288Krish-Makadiya wants to merge 4 commits into
Conversation
…on pages, and doubt management API routes.
|
@Krish-Makadiya is attempting to deploy a commit to the Karan Mani Tripathi 's projects Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
Fixes the AI solver /api/ask-ai 500 by adjusting the Neon/Drizzle database initialization, and includes additional TypeScript/syntax fixes to restore successful builds across several routes and auth pages.
Changes:
- Update
configs/db.tsxto initializedrizzle-orm/neon-httpdirectly with the connection string (avoids Neon helper crash). - Clean up reply action/vote endpoints (remove duplicate/incorrect variable usage and align request parsing with schema validation).
- Fix auth page syntax/structure issues and adjust doubts sorting code to satisfy TypeScript.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| configs/db.tsx | Changes Drizzle initialization to use the connection string directly (addresses runtime crash source). |
| app/api/replies/vote/route.ts | Removes redundant JSON parsing/validation in favor of centralized schema validation. |
| app/api/replies/action/[id]/route.ts | Fixes duplicate replyId handling and narrows destructured schema fields to what’s used. |
| app/api/doubts/route.ts | Adjusts sorting/pagination code to satisfy TS by casting (but reduces type safety). |
| app/(auth)/sign-up/[[...sign-up]]/page.tsx | Fixes page structure/syntax issues and reinstates “Back to Home” link with themed Clerk UI. |
| app/(auth)/sign-in/[[...sign-in]]/page.tsx | Fixes page structure/syntax issues and reinstates “Back to Home” link with themed Clerk UI. |
Comments suppressed due to low confidence (1)
app/api/doubts/route.ts:149
- The
(doubts as any[])cast on thesortdrops type safety understrictand makes comparator logic easy to break (e.g.,replyCount/createdAttypos won’t be caught). Prefer typing the mapped result asArray<typeof doubts[number] & { replyCount: number }>(or a dedicated DTO type) so bothsortand the laterslicecan stay fully typed withoutany.
doubts = (doubts as any[]).sort((a: any, b: any) => {
const pinnedDiff = pinnedScore(b.isPinned) - pinnedScore(a.isPinned);
if (pinnedDiff !== 0) return pinnedDiff;
if (sort === "popular") {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import { drizzle } from 'drizzle-orm/neon-http'; | ||
| import { neon } from '@neondatabase/serverless'; | ||
|
|
||
| const sql = neon(process.env.NEXT_PUBLIC_NEON_DB_CONNECTION_STRING!); | ||
| export const db = drizzle(sql); | ||
| export const db = drizzle(process.env.NEXT_PUBLIC_NEON_DB_CONNECTION_STRING!); | ||
|
|
|
Hi there! 👋 Thanks for your contribution to DoubtDesk. It looks like there are currently some merge conflicts between your branch and the Once the conflicts are resolved and the PR is clean, we'll be able to merge it! |
|
Ready to be merged, solved the Conflicts!! |
There was a problem hiding this comment.
Hi there! 👋 Thanks for your contribution to DoubtDesk.
It looks like there are currently some merge conflicts between your branch and the main branch. Could you please pull the latest changes from main, resolve the conflicts, and push the updates to this branch?
Once the conflicts are resolved and the PR is clean, we'll be able to merge it!
|
@copilot resolve the merge conflicts in this pull request |
Description
This PR resolves the
500 Internal Server Errorthat occurs when users submit questions to the AI solver.The runtime crash was caused by the way
drizzle-ormwas initialized using theneon()helper from@neondatabase/serverlessinsideconfigs/db.tsx. To fix this, the configuration was updated to pass the connection string directly into thedrizzle()initialization function, which is the recommended and stable syntax for moderndrizzle-ormversions.Additional Fixes Included to Unblock Builds:
app/(auth)/sign-in/[[...sign-in]]/page.tsxandapp/(auth)/sign-up/[[...sign-up]]/page.tsx.replyIdvariable declarations inapp/api/replies/action/[id]/route.tsandapp/api/replies/vote/route.ts.app/api/doubts/route.tsrelated to the dynamicreplyCountproperty during the array.sort()operation.app/api/replies/action/[id]/route.ts.Related Issue
Closes #14