
This is a hybrid Next.js + Python app that uses Next.js as the frontend and Flask as the API backend. One great use case of this is to write Next.js apps that use Python AI libraries on the backend.
This project uses Vercel Services to deploy a Next.js frontend and a Flask backend as part of a single Vercel project. Services are configured in vercel.json using the experimentalServices key:
//api/pythonVercel automatically routes requests to the correct service based on the URL path prefix. It also automatically injects environment variables based on the service name to easily route between services.
To make requests to the Python backend service and keep preview environments in sync without having to hard-code urls, NEXT_PUBLIC_BACKEND_URL is automatically set.
https://nextjs-flask-starter.vercel.app/
You can clone & deploy it to Vercel with one click:
You can clone & create this repo with the following command
npx create-next-app nextjs-flask --example "https://github.com/vercel/examples/tree/main/python/nextjs-flask"First, install the dependencies:
npm install# oryarn# orpnpm installThen, run both services locally:
vercel dev -LThe -L flag runs all services together locally without authenticating with the Vercel Cloud. Open http://localhost:3000 with your browser to see the result.