Hello, I’m trying to set up my FastAPI app on the Hobby plan and running into some issues which I think are easy to solve but I have little Vercel experience.
My repository has the following (somewhat atypical) structure
/api
/routes
/models
connection.py
main.py
/... other folders
.env
README.md
requirements.txt
vercel.json
So important here is that main.py
isn’t in the root directory (but in the /api
directory). To make sure Vercel correctly picks up on where to find it, I have set up vercel.json like this:
{
"builds": [
{
"src": "api/main.py",
"use": "@vercel/python"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "api/main.py"
}
]
}
However I get the following error screen with **500**: INTERNAL_SERVER_ERROR
:
And the following log:
[ERROR] Runtime.ImportModuleError: Unable to import module 'vc__handler__python': No module named 'connection'
Traceback (most recent call last):INIT_REPORT Init Duration: 1330.54 ms Phase: init Status: error Error Type: Runtime.Unknown
Inside main.py
helper functions from connection.py
are imported like this
from connection import get_driver
This all works fine on my local server but I think Vercel has issues with finding connection.py
because it goes looking for it in the root directory? I’m not sure though, it’s my best guess. How could I resolve this without moving everything in the /api
folder to the root folder?