Environment Variables
To get Blogify running locally or in a production environment, you need to configure environment variables for both the frontend (Next.js) and the backend (FastAPI). These variables allow the application to communicate with your database, authentication provider, and API services.
Configuration Overview
Blogify uses Supabase for authentication and storage, and MongoDB for post data and user profiles. You will need to create .env files in both the frontend and backend directories.
Frontend Variables
The frontend requires connection details for the Backend API and your Supabase project. Variables prefixed with NEXT_PUBLIC_ are accessible to the browser.
| Variable | Description | Example Value |
| :--- | :--- | :--- |
| NEXT_PUBLIC_API_URL | The base URL of your FastAPI backend service. | http://127.0.0.1:8000 |
| NEXT_PUBLIC_SUPABASE_URL | Your Supabase project URL (found in Project Settings > API). | https://xyz.supabase.co |
| NEXT_PUBLIC_SUPABASE_ANON_KEY | The public/anonymous API key for your Supabase project. | eyJhbGciOiJIUzI1Ni... |
Backend Variables
The backend requires credentials to connect to your MongoDB instance (either local or MongoDB Atlas).
| Variable | Description | Example Value |
| :--- | :--- | :--- |
| MONGODB_URI | The connection string for your MongoDB database. | mongodb://localhost:27017 |
| MONGODB_DB | The specific database name within your MongoDB instance. | blog_db |
Setting Up Your Files
Follow these steps to configure your environment:
1. Frontend Setup
Navigate to the frontend directory and create a file named .env.local:
# API Connection
NEXT_PUBLIC_API_URL=http://127.0.0.1:8000
# Supabase Configuration
NEXT_PUBLIC_SUPABASE_URL=https://your-project-id.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-public-anon-key
2. Backend Setup
Navigate to the root or backend directory (depending on your deployment structure) and create a .env file:
# MongoDB Connection
MONGODB_URI=mongodb://localhost:27017
MONGODB_DB=blog_db
Security Best Practices
- Never commit
.envfiles: Ensure that.env,.env.local, and.env.revealare included in your.gitignorefile to prevent leaking sensitive credentials. - Production Keys: When deploying to Vercel (Frontend) or Railway (Backend), add these variables directly into the provider's dashboard under the "Environment Variables" section.
- Supabase RLS: While the
ANON_KEYis public, ensure you have Row Level Security (RLS) enabled on your Supabase tables to protect user data.