Problem:
My python serverless functions (FastAPI) don’t work on my “vercel dev” local environment. They work perfectly fine on production, preview, and running “next dev” locally concurrently with my FastAPI server.
Current behavior:
I’ve have a test endpoint, /api, on all three of my environments. When I connect to this endpoint on prod, preview, or running next dev locally (not “vercel dev”), it connects perfectly fine. However, only specifically when running “vercel dev”, the endpoint returns a 404 error.
My Next.js (app router) directory structure:
root/
│── api/
│ ├── index.py
│ └── requirements.txt
On production and preview, I don’t use a vercel.json file and everything works fine. But this is what I’ve came up with during troubleshooting to see if this works for development. This doesn’t seem to work either.
## Vercel.json
{
"functions": {
"api/*.py": {
"runtime": "@vercel/python@3.12.1" #same python version running on my system
}
},
"routes": [
{
"src": "/api/(.*)",
"dest": "api/index.py"
}
]
}
My package.json scripts config:
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
}
Build Settings:
All project build settings are untouched on my vercel project environment.
How to replicate:
I’ve created a test project you can visit at https://testproject-rho-one.vercel.app/api
Github repo: GitHub - brandoncintron/testrepo (this is just a default nextjs app with app router, freshly created as I posted this.)
You will see that you can see the helloworld message, but if you clone the repo code and run it with “vercel dev”, it does not allow you to access the /api endpoint.
Any help would be appreciated, thanks!