Skip to content

Instantly share code, notes, and snippets.

@CraftsMan-Labs
Last active July 27, 2024 15:59
Show Gist options
  • Select an option

  • Save CraftsMan-Labs/a214116a40b767fffb1065db7f02b380 to your computer and use it in GitHub Desktop.

Select an option

Save CraftsMan-Labs/a214116a40b767fffb1065db7f02b380 to your computer and use it in GitHub Desktop.
  1. Set up your development environment:

Install Python and pip if you haven't already. Then, create a new directory for your project and set up a virtual environment:

Install Node JS

https://nodejs.org/en/download/package-manager

mkdir flask-vercel-app
cd flask-vercel-app
python -m venv venv
source venv/bin/activate  # On Windows, use: venv\Scripts\activate
  1. Install Flask:

Go to your terminal and install Flask using the below command.

pip install Flask

Create a github project in git and clone that project to you local

  1. Create your Flask application:

Create a file named index.py in your project directory with the following content:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello_world():
    return "Hello, World!"

if __name__ == "__main__":
    app.run()
  1. Create a requirements.txt file by running this command in the same terminal:
pip freeze > requirements.txt
  1. Create a vercel.json configuration file:

Create a file named vercel.json in your project directory with the following content:

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

Visit http://localhost:5000 in your browser to see your app running.

  1. Set up version control (optional but recommended):

Initialize a Git repository and commit your changes:

git init
git add .
git commit -m "Initial commit"
  1. Deploy to Vercel:

First, install the Vercel CLI:

npm install -g vercel

Then, deploy your application:

vercel

Follow the prompts to log in or create a Vercel account if you haven't already. Choose the appropriate project settings when prompted.

  1. Access your deployed application:

After the deployment is complete, Vercel will provide you with a URL where your application is live. You can visit this URL to see your Flask app running on Vercel.

  1. For future updates:

Whenever you make changes to your application, you can redeploy by running:

vercel --prod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment