Repository navigation
fix(api): preserve original request path in Vercel Python runtime - #3
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.jsonantigo (rewrites: /(.*)->/api/index), o Flask passou a receberPATH_INFO=/api/indexpara 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+routescomdestpara 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"}[1,2,3]→ 400 estruturado