Required Environment Variables
The application requires three essential environment variables to function properly:The base URL of your Bun Hono backend server.Default:
http://localhost:3000If your backend is running on a different port or host, update this value accordingly.The username for Basic Authentication with the backend API.Important: This must match the username configured in your Bun Hono backend.
The password for Basic Authentication with the backend API.Important: This must match the password configured in your Bun Hono backend.
Setup Instructions
Add environment variables
Add the following variables to your
.env file:.env
The
USERNAME and PASSWORD values should match the credentials you configured in your Bun Hono backend.Port Configuration
If your backend is running on port 3000, the Next.js frontend will automatically run on port 3001 to avoid conflicts.
BACKEND_URL accordingly:
.env
How Environment Variables Are Used
These environment variables are accessed in server actions throughout the application. Here’s how they’re used:Backend URL
TheBACKEND_URL is used to construct API endpoints:
src/lib/actions/message/createMessage.ts
Authentication Credentials
TheUSERNAME and PASSWORD are encoded as Base64 for Basic Authentication:
Security Best Practices
Use strong passwords
Use strong, unique passwords for the
PASSWORD variable, especially in production environments.Troubleshooting
Connection Refused
If you see connection errors, verify:- The backend server is running
- The
BACKEND_URLmatches the backend’s actual URL and port - There are no firewall rules blocking the connection
Authentication Errors
If you receive 401 Unauthorized errors:- Verify
USERNAMEandPASSWORDmatch the backend configuration - Check for extra spaces or quotes in your
.envfile - Restart the development server after changing credentials
Environment Variables Not Loading
Next.js only loads environment variables on server startup. You must restart the development server after modifying the
.env file.- Restart the development server
- Verify the
.envfile is in the project root - Check that variable names are spelled correctly
- Ensure there are no syntax errors in the
.envfile