Skip to content

fix(api): preserve original request path in Vercel Python runtime - #3

Merged
BarujaFe1 merged 1 commit into
mainfrom
fix/vercel-wsgi-routing
Aug 21, 2026
Merged

BarujaFe1 merged 1 commit into
mainfrom
fix/vercel-wsgi-routing

Conversation

@BarujaFe1

Copy link
Copy Markdown
Owner

Contexto

Após o merge do #2, o redeploy da API quebrou: todo request retornava 404 do Flask (inclusive /api/health).

Causa raiz (verificada empiricamente)

O runtime Python do Vercel mudou a forma como rewrites chegam ao WSGI: com o vercel.json antigo (rewrites: /(.*)->/api/index), o Flask passou a receber PATH_INFO=/api/index para qualquer rota — o path original não existe em nenbum header do environ (confirmado com catch-all de diagnóstico que dumpou o environ em produção). Ou seja: o rewrite destrói a roteabilidade da app WSGI.

Fix

Trocar para o roteamento clássico builds + routes com dest para o arquivo da função, que preserva o path original no environ WSGI:

{"builds": [{"src": "api/index.py", "use": "@vercel/python"}], "routes": [{"src": "/(.*)", "dest": "api/index.py"}]}

Verificação em produção (já deployado manualmente)

  • /api/health → 200 {"status":"ok"}
  • caso P0 (A=60% vs B=58%) → Regressão, p=0.004, IC negativo
  • body lista [1,2,3] → 400 estruturado

The Vercel Python runtime changed how rewrites reach WSGI: a request to
/api/analyze rewritten to /api/index now surfaces PATH_INFO=/api/index to
Flask, so every route 404ed (the original path is not recoverable from any
environ header - verified with a temporary catch-all probe). Switch
vercel.json from the modern rewrite to the classic builds+routes routing
(dest to the function file), which preserves the original request path in
the WSGI environ. Verified in production: /api/health, /api/analyze and
structured 400s all respond correctly.
@BarujaFe1
BarujaFe1 merged commit 06a4767 into main Aug 21, 2026
2 checks passed
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.

1 participant