I wanted to make a website using flask and fastapi
So here’s what i ended with :
import uvicorn
from starlette.middleware.wsgi import WSGIMiddleware
from starlette.applications import Starlette
from starlette.routing import Mount
from flask import Flask
from fastapi import FastAPI
flask_app = Flask(__name__)
@flask_app.route('/')
def home():
return "Hello from flask"
fastapi_app = FastAPI()
@fastapi_app.get("/test")
def test():
return "Hello from api"
flask_asgi_app = WSGIMiddleware(flask_app)
routes = [
Mount('/api', app=fastapi_app),
Mount('/', app=flask_asgi_app),
]
app = Starlette(routes=routes)
if __name__ == "__main__":
uvicorn.run(app)
It work fine on my pc (using python main.py
or uvicorn main:app
)
But when i try to upload the projet to vercel (dont forget the following files)
requirements.txt
Flask
fastapi
uvicorn
starlette
vercel.json
{
"version": 2,
"builds": [
{
"src": "main.py",
"use": "@vercel/python"
}
],
"routes": [
{
"src": "(.*)",
"dest": "main.py"
}
]
}
I run vercel dev
(on my pc)
And got theses error :
<class 'TypeError'>
LambdaError: Unspecified runtime initialization error
at Lambda.<anonymous> (C:UsersxAppDataRoamingnpmnode_modulesvercelnode_modules@vercelfundistsrcindex.js:110:27)
at Generator.next (<anonymous>)
at fulfilled (C:UsersxAppDataRoamingnpmnode_modulesvercelnode_modules@vercelfundistsrcindex.js:24:58)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
I cant figure out what does that mean, i found pretty much nothing on google
Long time ago i try pretty much the same thing but uploading directly to vercel (without trying self hosted with vercel dev) and instead of showing the page it only download them
Not sure if its related or no
Whatever, does anybody know why i got the error, what does it mean and how to solve it ?
Lande is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.