Skip to content

Remove PHP /api/ai endpoint and consolidate AI routing to Node/Vercel function#3

Open
setu102 wants to merge 14 commits intomainfrom
codex/apply-changes-2nkm8k
Open

Remove PHP /api/ai endpoint and consolidate AI routing to Node/Vercel function#3
setu102 wants to merge 14 commits intomainfrom
codex/apply-changes-2nkm8k

Conversation

@setu102
Copy link
Copy Markdown
Owner

@setu102 setu102 commented Feb 3, 2026

Motivation

  • Remove the PHP /api/ai proxy because Vercel does not support PHP and it conflicted with the serverless route.
  • Centralize all AI traffic to a single Node/Vercel handler so the Gemini API key is never exposed to the browser.

Description

  • Deleted the PHP endpoint file api/ai.php so only the Node serverless function api/ai.js serves /api/ai requests.
  • Added/kept api/ai.js which validates contents as an array, reads GEMINI_API_KEY/GEMINI_MODEL, calls @google/genai and returns text and groundingMetadata with clear HTTP error codes.
  • Updated frontend calls in db.ts to POST AI requests to /api/ai (Node/Vercel function) and to surface server error messages when the response is non-OK.
  • Hardened server.js to use GEMINI_API_KEY or API_KEY, use the configured model, validate contents, and return consistent JSON errors for missing config or malformed requests.

Testing

  • No automated tests were run for these changes.

Codex Task

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
amar-apps Error Error Feb 3, 2026 11:50am
amar-apps-f86a Error Error Feb 3, 2026 11:50am

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread db.ts
Comment on lines +12 to +17
const response = await fetch('/api/ai', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment thread api/ai.js Outdated
Comment on lines +26 to +27
const body = typeof req.body === 'string' ? JSON.parse(req.body) : req.body;
const { contents, systemInstruction, tools, responseSchema, responseMimeType } = body || {};
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant