This document explains how to run the AirAlert Pro frontend application with mock data, making it completely self-contained and deployable without a backend.
The frontend application has been enhanced to work with a mock API that provides realistic demo data. This allows the application to:
- Run completely standalone without any backend
- Display realistic air quality data for demonstration
- Maintain all functionality including the Gemini AI chatbot
- Be easily deployed to hosting platforms like Vercel
- No Backend Required: All data is generated by the mock API
- Realistic Demo Data: Air quality values, forecasts, and trends that look real
- Full Functionality: All pages and features work with mock data
- Gemini AI Chatbot: Works with your provided API key
- Easy Deployment: Can be deployed to Vercel with a single click
The application includes a comprehensive mock data generator that creates realistic air quality data for Goa, India, including:
- Current air quality measurements
- 24-hour forecasts
- Historical trends
- Health recommendations
- Pollutant breakdowns
- Alerts and emergency notifications
The API service automatically switches between real and mock APIs based on configuration:
- When
VITE_API_URLcontains "mock-api", mock data is used - When running in development mode, mock data is used by default
- All API endpoints are supported with realistic mock responses
When deployed to Vercel, API requests are automatically routed to the mock API handler.
The .env file is already configured for mock data:
VITE_API_URL=http://localhost:5173/mock-api
VITE_GEMINI_API_KEY=AIzaSyBtgRmkYVpxsCuSpYdYbHJATwAy82Yt1Ds
cd frontend
npm installnpm run devThe application will be available at http://localhost:5173 with mock data.
npm run buildThe built files will be in the dist directory.
- Push your code to a GitHub repository
- Create a new project on Vercel
- Connect your repository
- Set environment variables:
VITE_GEMINI_API_KEY: Your Gemini API key
- Deploy!
The application will automatically use the mock API when deployed to Vercel.
To customize the mock data:
- Edit
src/services/mockApi.js - Adjust value ranges in the generation functions
- Modify locations in the
locationsarray - Change AQI categories or calculation methods
To add new mock endpoints:
- Add a new method to the
MockApiServiceclass - Add the endpoint to the Vercel handler in
mock-api-handler.js - Add the method to the
airQualityAPIobject inapi.js
Run the test script to verify mock data generation:
cd frontend
node test-mock-api.jsWhen running the development server, you can test API endpoints directly:
http://localhost:5173/mock-api/currenthttp://localhost:5173/mock-api/forecasthttp://localhost:5173/mock-api/locations
The chatbot functionality works with your Gemini API key:
- All air quality data is contextualized in chat responses
- Health recommendations are based on current mock data
- The chatbot provides realistic responses about air quality
-
Blank Pages:
- Check browser console for errors
- Verify all dependencies are installed
-
API Errors:
- Ensure
VITE_API_URLis correctly configured - Check that the mock API handler is working
- Ensure
-
Chatbot Not Responding:
- Verify
VITE_GEMINI_API_KEYis set correctly - Check browser console for Gemini API errors
- Verify
- Check the browser console for detailed error messages
- Refer to
MOCK_API.mdfor detailed documentation - Review the mock data generation in
src/services/mockApi.js
- Zero Backend Dependency: Run the complete application with just static files
- Easy Deployment: Deploy to any static hosting platform
- Realistic Demo: Impress users with realistic data without real APIs
- Development Friendly: Work offline without internet connectivity
- Cost Effective: No backend hosting costs for demos and showcases
The AirAlert Pro frontend with mock API provides a complete, professional demonstration of the application without requiring any backend infrastructure.