How to deploy a full-stack Next.js and FastAPI application on Vercel for free #90367
Replies: 3 comments
|
Nice guide and architecture diagram 👍 Splitting the deployment into two Vercel projects (Next.js frontend + FastAPI backend) with Neon Postgres is a clean way to stay within the free tier. One additional tip that may help others: If the Next.js app and FastAPI API are deployed separately, you can simplify communication by setting the backend URL as an environment variable in the frontend: Then call the API like: fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/endpoint`)Also ensure CORS is enabled in FastAPI so the Vercel frontend can access it. Overall this is a clear and practical example for deploying Next.js + FastAPI without Docker or custom infrastructure. Thanks for sharing the repo and detailed walkthrough. |
|
Disclaimer: I work at Vercel so feel free to ask questions! Deploying a FastAPI + NextJS apps on Vercel is super easy today with Vercel Services. Docs: https://vercel.com/docs/services (feel free to also give the docs to your coding agent, they'll be able to follow and do it quickly) Advantages of using Services:
We're evolving Vercel Services into the most capable way on the internet to host your Python/Go/Rust + frontend code, regardless of its complexity and scale. |
|
One deployment detail that is easy to miss is that NEXT_PUBLIC_API_URL is embedded into the browser bundle at build time. It is fine for a public FastAPI base URL, but it must not contain credentials or other secrets. Keep private values in server-only environment variables. For the FastAPI deployment, configure CORS with the exact frontend origins you actually use, including the production URL and any preview URL pattern you intentionally support. Also make sure the API handles OPTIONS requests and that the frontend does not accidentally call localhost in a production build. For a production-style setup, I would add a small /health endpoint, run a database migration or connectivity check separately from the first request, and use Neon's pooled connection string for serverless workloads. The two-project architecture is a sensible free-tier baseline; these details are the parts that usually cause confusing deployment failures. |
Uh oh!
There was an error while loading. Please reload this page.
Deploying to Vercel may seem obvious and straightforward, but doing it properly for a full-stack FastAPI and Next.js project still takes some time and effort. You need to configure the project carefully and review several parts of the documentation to get everything right.
I went through this process myself recently and took note of all the tricky and ambiguous parts, then consolidated everything into a clear, step-by-step guide. This is not meant to be a comprehensive overview of Vercel, there is already documentation for that, but rather a practical procedure that you can follow with minimal guesswork to achieve a fully functional demo deployment while staying within the free tier.
The article walks through structuring the backend and frontend as separate deployments, handling environment variables correctly, integrating Neon Postgres. It focuses on CLI-based deployment, but also describes one-click Vercel Deploy buttons, with a complete, ready-to-run repository.
If you're trying to host a FastAPI + Next.js app on Vercel without Docker, custom proxies, or guesswork, this should save you a lot of time.
Here is the link to the article:
https://nemanjamitic.com/blog/2026-02-22-vercel-deploy-fastapi-nextjs
Repository (and branch) with the demo app and configuration:
https://github.com/nemanjam/full-stack-fastapi-template-nextjs/tree/vercel-deploy
Have you done something similar yourself and used a different approach? I am looking forward to your feedback and discussion.
All reactions