Stop Deploying Frontend and Backend Separately: Let Your Backend Serve the Frontend
Most of us follow a common project structure:
frontend/ → React / Angular / Vue
backend/ → Node / Java / Python
We deploy:
- Frontend to Netlify, Vercel, or S3
- Backend to EC2, Heroku, or some server
This works, but it also adds extra complexity:
- Two deployments
- CORS issues
- Separate domains and SSL configs
- More infrastructure to manage
Recently, I came across a simpler and cleaner approach —
deploy only the backend, and let it serve the frontend as well.
And honestly… it’s an awesome concept.
What Does “Backend Serves Frontend” Mean?
In this approach:
- You still develop frontend and backend separately
- But during deployment, the backend serves the frontend’s built files
So instead of hosting two applications, you host only one server.
That server:
- Serves API endpoints (
/api/*) - Serves frontend UI (
/)
How It Works (High Level)
1. Build the Frontend
Frontend frameworks like React, Vue, or Angular produce static files:
index.html
main.js
assets/
This is done using:
npm run build
2. Backend Serves the Built Files
The backend is configured to:
- Serve these static files
- Handle API requests
So:
https://myapp.com→ Frontend UIhttps://myapp.com/api/users→ Backend API
All from one server.
Typical Project Structure
project/
├── frontend/
│ └── React / Vue / Angular source
├── backend/
│ ├── server code
│ └── build/ ← frontend build output
Or a monorepo style:
project/
├── client/
├── server/
└── package.json
Why This Approach Is So Powerful
✅ Only One Deployment
No need to deploy frontend and backend separately.
✅ No CORS Problems
Frontend and backend share the same origin.
✅ Simplified Infrastructure
One server, one domain, one SSL certificate.
✅ Faster Development for Small Teams
Less DevOps overhead, fewer moving parts.
Is This a New Concept?
Not really.
Before modern SPAs:
- JSP
- Thymeleaf
- PHP
- ASP.NET
Backends always served the UI.
Modern tools just brought this idea back — but with React, Vue, and Angular.
Frameworks like:
- Next.js
- Nuxt
- Spring Boot
- Django
All support this pattern naturally.
When Should You Use This?
Best Use Cases
- MVPs
- Small to medium applications
- Internal tools
- Early-stage startups
When to Avoid
- Extremely high frontend traffic
- Frontend and backend need independent scaling
- Multiple frontend apps using the same backend
Final Thoughts
If your frontend is ultimately just static files, there’s no strict need to host it separately.
Letting your backend serve the frontend:
- Reduces complexity
- Avoids unnecessary infrastructure
- Makes deployments cleaner and faster
Sometimes, the simplest architecture is the best one.
Happy Learning 🚀
Comments
Post a Comment