Dan M
Dan M

Reputation: 11

Issue with deploying a flask app on Vercel

Does anyone have any experience with deploying flask apps on Vercel? I have a Flask app that's on a gitHub repository. Currently, it's deployed on render.com (on a free tier) and works fine, but has a slow initial loading time. I've been trying to deploy it on Vercel, hoping it will be able to load faster. It's worth noting that Vercel gives you the option to define a framework for the build of your project. It has a nice selection of frameworks, which does not include flask.

I've connected the repository to a Vercel project and added a vercel.json file to the project with the following code:

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

However, all I was able to get was a seemingly successful deployment, but when trying to load the app on the browser there's an error message:

This Serverless Function has crashed.
Your connection is working correctly.
Vercel is working correctly.

500: INTERNAL_SERVER_ERROR
Code: FUNCTION_INVOCATION_FAILED
ID: sfo1::ft28b-1701147447712-8bb4b61991f8

Seems like I'm missing some crucial pieces in the build process. Any ideas? Or alternatively, any free platform for flask deployments that is faster than render.com?

Any help will be appreciated.

Upvotes: 1

Views: 910

Answers (1)

Deni Docc
Deni Docc

Reputation: 21

I had such a problem, below is how I solved it:

  1. Check app.py (or your corresponding Flask app module) for syntax errors.
  2. My json file looks like this (I have one route):
{
    "builds": [

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

Upvotes: 1

Related Questions