Skip to content

fix: add root Vercel API rewrite and robust frontend error handling - #70

Merged
Benevanio merged 1 commit into
developfrom
feature/vps-secure-integration
Apr 7, 2026
Merged

Benevanio merged 1 commit into
developfrom
feature/vps-secure-integration

Conversation

@Benevanio

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings April 7, 2026 15:18
@Benevanio
Benevanio merged commit b108983 into develop Apr 7, 2026
4 checks passed
@Benevanio Benevanio self-assigned this Apr 7, 2026
@github-project-automation github-project-automation Bot moved this from Backlog to Done in JobAtlas – Kanban Apr 7, 2026
@vercel

vercel Bot commented Apr 7, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
painel-vagas Ready Ready Preview, Comment Apr 7, 2026 3:19pm

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a Vercel edge rewrite for /api/* requests at the repo root and updates the frontend jobsService to produce more user-friendly errors when the backend/proxy returns non-JSON responses.

Changes:

  • Added vercel.json rewrite rules to forward /api/* to the external backend host.
  • Introduced a readPayload helper in frontend/src/services/jobsService.ts to handle non-JSON error bodies more gracefully.
  • Added a unit test covering the “non-JSON error response” scenario for fetchKeywords.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
vercel.json Adds root-level /api/* rewrite to external backend.
frontend/src/services/jobsService.ts Centralizes response payload parsing with JSON/text fallback for error handling.
frontend/tests/unit/utils/jobsService.test.ts Adds coverage for readable errors when the response isn’t JSON.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +22 to +37
async function readPayload(response: Response): Promise<Record<string, unknown>> {
const contentType = response.headers?.get?.("content-type") ?? "";

if (!contentType || contentType.includes("application/json")) {
try {
const payload = await response.json();
return payload && typeof payload === "object" ? (payload as Record<string, unknown>) : {};
} catch {
// Fallback below for non-JSON bodies returned by proxies/platforms.
}
}

if (typeof response.text === "function") {
const text = await response.text();
return text ? { message: text } : {};
}

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

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

readPayload tenta response.json() e, se isso falhar, faz fallback para response.text(). Em fetch, o body do Response é um stream que só pode ser consumido uma vez; se json() já leu o body (mesmo lançando por JSON inválido ou body vazio), text() vai falhar com erro de stream já lido. Para tornar o fallback realmente robusto, use response.clone() antes de ler, ou leia text() uma vez e faça JSON.parse condicionalmente (mantendo o texto para a mensagem de erro).

Copilot uses AI. Check for mistakes.
Comment thread vercel.json
"rewrites": [
{
"source": "/api/(.*)",
"destination": "http://jobsglobalscraper.ddns.net/api/$1"

Copilot AI Apr 7, 2026

Copy link

Choose a reason for hiding this comment

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

O rewrite aponta para http://jobsglobalscraper.ddns.net/... (HTTP). Isso remove TLS entre a infraestrutura da Vercel e a API e também pode ser bloqueado/alterado por redirecionamentos. Como o código/testes já usam https://jobsglobalscraper.ddns.net/ como base (ex.: testes de VITE_API_BASE_URL), alinhe o rewrite para https://... (ou documente/garanta explicitamente que o backend só serve HTTP).

Suggested change
"destination": "http://jobsglobalscraper.ddns.net/api/$1"
"destination": "https://jobsglobalscraper.ddns.net/api/$1"

Copilot uses AI. Check for mistakes.

This branch was previously deployed

1 inactive deployment
Preview — 72e55bbe Deployed Apr 7, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants