Remove PHP /api/ai endpoint and consolidate AI routing to Node/Vercel function#3
Remove PHP /api/ai endpoint and consolidate AI routing to Node/Vercel function#3
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 601450e359
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const response = await fetch('/api/ai', { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json' | ||
| }, | ||
| body: JSON.stringify({ |
There was a problem hiding this comment.
Preserve cPanel/static deployments for /api/ai
db.callAI now always POSTs to /api/ai, but this commit removed the only non-Node handler (api/ai.php) while README_CPANEL_HOSTING.md still documents a static/cPanel deployment flow. In that environment there is no /api/ai endpoint at all, so AI calls will start returning 404 and the core feature breaks. If cPanel/static hosting is still supported, keep a PHP proxy or add a conditional fallback/update the routing; otherwise the docs should be updated to avoid directing users to a broken path.
Useful? React with 👍 / 👎.
| const body = typeof req.body === 'string' ? JSON.parse(req.body) : req.body; | ||
| const { contents, systemInstruction, tools, responseSchema, responseMimeType } = body || {}; |
There was a problem hiding this comment.
Guard JSON.parse to avoid unhandled 500s
The handler unconditionally runs JSON.parse(req.body) when req.body is a string. If a client sends invalid JSON (or the platform forwards a non-JSON string), this throws before any response is written, yielding a generic 500 instead of a controlled 400 with a clear error. Wrapping the parse in a try/catch and returning a 400 avoids an unhandled exception and gives clients a deterministic error response.
Useful? React with 👍 / 👎.
Motivation
/api/aiproxy because Vercel does not support PHP and it conflicted with the serverless route.Description
api/ai.phpso only the Node serverless functionapi/ai.jsserves/api/airequests.api/ai.jswhich validatescontentsas an array, readsGEMINI_API_KEY/GEMINI_MODEL, calls@google/genaiand returnstextandgroundingMetadatawith clear HTTP error codes.db.tstoPOSTAI requests to/api/ai(Node/Vercel function) and to surface server error messages when the response is non-OK.server.jsto useGEMINI_API_KEYorAPI_KEY, use the configured model, validatecontents, and return consistent JSON errors for missing config or malformed requests.Testing
Codex Task