This guide explains how to deploy your DevBlog application with the frontend connected to the backend API.
Your DevBlog application consists of:
- Frontend: Next.js application (currently deployed at https://dev-blog-three-blue.vercel.app/)
- Backend: NestJS API with PostgreSQL database
First, you need to deploy your backend. Here are the steps for popular platforms:
- Push your backend code to GitHub
- Connect your GitHub repo to Render
- Create a new Web Service
- Set build command:
npm install && npm run build - Set start command:
npm run start:prod - Add environment variables:
DATABASE_URL: Your PostgreSQL connection stringJWT_SECRET: A secure random stringNODE_ENV:production
- Install Railway CLI:
npm install -g @railway/cli - Login:
railway login - In your backend directory:
railway init - Deploy:
railway up - Add PostgreSQL:
railway add postgresql - Set environment variables in Railway dashboard
Make sure your backend has these environment variables:
DATABASE_URL=postgresql://username:password@host:port/database
JWT_SECRET=your-super-secret-jwt-key
NODE_ENV=production
PORT=3000Ensure your backend allows CORS for your frontend domain. In your main.ts:
app.enableCors({
origin: ['https://dev-blog-three-blue.vercel.app', 'http://localhost:3000'],
credentials: true,
});In your Vercel dashboard, add the environment variable:
NEXT_PUBLIC_API_URL: Your deployed backend URL (e.g.,https://your-backend.onrender.com)
After setting the environment variable, trigger a new deployment in Vercel.
cd backend
npm install
# Set up your .env file with DATABASE_URL and JWT_SECRET
npm run start:dev# In root directory
npm install
# Make sure .env.local has NEXT_PUBLIC_API_URL=http://localhost:3000
npm run devYour backend should expose these endpoints:
POST /auth/login- User loginPOST /auth/register- User registration
GET /users/me- Get current user profileGET /users/me/articles- Get current user's articlesGET /users/:username- Get user by username
GET /articles- Get all published articlesGET /articles/:id- Get article by IDPOST /articles- Create new article (authenticated)PUT /articles/:id- Update article (authenticated)DELETE /articles/:id- Delete article (authenticated)
GET /analytics- Get analytics data (authenticated)
Make sure your Prisma schema matches the expected structure:
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
password String
avatar String?
bio String?
website String?
location String?
username String? @unique
createdAt DateTime @default(now())
articles Article[]
}
model Article {
id Int @id @default(autoincrement())
title String
excerpt String?
content String?
status String @default("draft")
publishedAt DateTime?
views Int @default(0)
likes Int @default(0)
comments Int @default(0)
readTime Int?
authorId Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
author User @relation(fields: [authorId], references: [id])
}- Visit your deployed frontend
- Try registering a new account
- Try logging in with the account
- Check if the dashboard loads with user data
- Create a new article in the editor
- Check if it appears in your dashboard
- Verify articles appear on the home page
- Make sure your backend allows your frontend domain in CORS settings
- Check that credentials are properly configured
- Verify JWT tokens are being sent correctly
- Check that JWT_SECRET matches between requests
- Verify DATABASE_URL is correct
- Run
npx prisma migrate deployin production - Run
npx prisma generateafter schema changes
NEXT_PUBLIC_API_URL=https://your-backend-url.comDATABASE_URL=postgresql://...
JWT_SECRET=your-secret-key
NODE_ENV=production
PORT=3000- Deploy your backend to your preferred platform
- Update the
NEXT_PUBLIC_API_URLin Vercel - Test all functionality
- Monitor logs for any issues
Your DevBlog application should now be fully connected and functional!