The backend must be running before you start the frontend. The frontend depends on
NEXT_PUBLIC_API_BASE_URL to communicate with the API.Navigate to the frontend directory
From the repository root:Install dependencies
If you haven’t already installed all workspace dependencies from the root, install them now:Configure environment variables
Create a.env.local file in the frontend/ directory. Next.js reads this file automatically during development and build.
Environment variable reference
| Variable | Description | Example |
|---|---|---|
NEXT_PUBLIC_API_BASE_URL | The full URL of the running Hayon backend | http://localhost:5000 |
NEXT_PUBLIC_GOOGLE_CLIENT_ID | Google OAuth 2.0 client ID, used for the Google sign-in button | 123456789-xxxx.apps.googleusercontent.com |
Start the development server
http://localhost:3000.
The dev script runs Next.js with the webpack bundler explicitly:
The frontend runs on port 3000 by default. The backend runs on port 5000. Make sure
NEXT_PUBLIC_API_BASE_URL matches the actual backend port.Available scripts
| Script | Command | Description |
|---|---|---|
| Development server | pnpm run dev | Starts the Next.js dev server with hot reload |
| Build | pnpm run build | Compiles and optimises the app for production |
| Production server | pnpm run start | Starts the compiled production build |
| Lint | pnpm run lint | Runs ESLint on all files |
| Format | pnpm run format | Runs Prettier on all files |
Production deployment on Vercel
Hayon’s frontend is designed to deploy to Vercel, which provides zero-configuration deployment for Next.js apps.Push your code to GitHub
Make sure your latest changes are committed and pushed to a GitHub repository.
Import the project in Vercel
- Log in to vercel.com.
- Click Add New > Project.
- Import your GitHub repository.
- Set the Root Directory to
frontend. - Vercel will automatically detect the Next.js framework.
Configure environment variables in Vercel
In the Vercel project settings, navigate to Settings > Environment Variables and add:
Set these for the Production, Preview, and Development environments as appropriate.
| Variable | Value |
|---|---|
NEXT_PUBLIC_API_BASE_URL | Your production backend URL (e.g., https://api.yourdomain.com) |
NEXT_PUBLIC_GOOGLE_CLIENT_ID | Your Google OAuth client ID |
CORS configuration
The backend enforces strict CORS. Only requests from the origin specified inFRONTEND_URL (a backend environment variable) are allowed.
Ensure the following values match exactly:
| Backend variable | Frontend origin |
|---|---|
FRONTEND_URL=http://localhost:3000 | Development frontend at http://localhost:3000 |
FRONTEND_URL=https://app.yourdomain.com | Production Vercel deployment URL |
Adding a custom domain in Vercel
If you assign a custom domain to your Vercel deployment:- Go to Settings > Domains in your Vercel project.
- Add your domain (e.g.,
app.yourdomain.com). - Update
FRONTEND_URLin your backend environment to match the new domain. - Redeploy the backend so the change takes effect.
Connecting to the backend WebSocket
The frontend connects to the backend over Socket.IO for real-time notifications. The WebSocket connection is established using the same base URL as the REST API (NEXT_PUBLIC_API_BASE_URL).
Make sure your production backend URL supports WebSocket connections. If you are using Nginx as a reverse proxy, include the WebSocket upgrade headers in your Nginx configuration (see Backend setup).
Troubleshooting
API requests fail with a CORS error
API requests fail with a CORS error
Check that the
FRONTEND_URL environment variable on the backend matches the exact origin of the running frontend, including the protocol (http vs https) and port.Google sign-in button does not appear
Google sign-in button does not appear
Socket.IO connection fails
Socket.IO connection fails
Ensure the backend is running and that
NEXT_PUBLIC_API_BASE_URL points to the correct host and port. Check the browser console for the specific WebSocket error.Build fails with TypeScript errors
Build fails with TypeScript errors
Run
pnpm run lint to identify type errors. Ensure you are using the correct Node.js and pnpm versions (see Prerequisites).