Required Environment Variables
NEPAL_ADMIN_DATA_URL
The primary environment variable used by the application to fetch administrative division data. Purpose: Specifies the URL from which the application fetches Nepal’s administrative division data (provinces, districts, and municipalities). Type: String (URL) Required: Yes Example:How It Works
The application uses this environment variable inapp.py to fetch data at startup:
app.py
Fallback Behavior
If the URL specified inNEPAL_ADMIN_DATA_URL is unavailable or returns an error:
- The application logs the error with status code and response text
- Falls back to a local JSON file:
data/updated_nepal_data.json - Continues operation using the local data
The fallback mechanism ensures the application can still run during development even if the remote data source is temporarily unavailable. However, for production deployments on Vercel, ensure the URL is always accessible as local files may not be available in the serverless environment.
Configuration by Environment
Local Development
For local development, use a.env file in the project root directory:
Vercel Deployment
For production deployment on Vercel, configure environment variables through the Vercel dashboard:Access Project Settings
- Log in to Vercel Dashboard
- Select your project
- Navigate to Settings → Environment Variables
Add Environment Variable
- Click Add New
- Enter the key:
NEPAL_ADMIN_DATA_URL - Enter the value: Your data source URL
- Select environments:
- ✓ Production
- ✓ Preview
- ✓ Development
- Click Save
Using Vercel CLI
Alternatively, set environment variables using the Vercel CLI:Data Source Requirements
The URL specified inNEPAL_ADMIN_DATA_URL must:
- Return a JSON response with administrative division data
- Be publicly accessible (or use authentication if supported)
- Follow the expected data structure:
Troubleshooting
Error: “NEPAL_ADMIN_DATA_URL not found”
Cause: The environment variable is not set or not loaded correctly. Solution:- For local development: Ensure
.envfile exists in the project root with the correct variable - For Vercel: Verify the environment variable is set in project settings and redeploy
Error: “Error fetching data: 404”
Cause: The URL specified inNEPAL_ADMIN_DATA_URL is not accessible.
Solution:
- Verify the URL is correct and publicly accessible
- Test the URL in a browser or using
curl: - Check if the URL requires authentication or has CORS restrictions
Fallback to Local Data
Cause: Remote data source failed, application using local fallback. Solution:- Check the console logs for the specific error message
- Verify network connectivity
- Ensure the remote server is operational
- Consider hosting the data on a reliable CDN or static hosting service
Best Practices
- Use Reliable Hosting: Host your data JSON file on a reliable service (GitHub Pages, Vercel, Netlify, or a CDN)
- Version Control: Keep your data source under version control to track changes
- Environment Separation: Use different URLs for development, staging, and production environments
- Security: If your data is sensitive, use authentication headers (requires code modification)
- Monitoring: Set up monitoring to alert you if the data source becomes unavailable
- Backup: Keep a local copy of the data for emergency fallback scenarios
Next Steps
- Learn how to set up local development
- Deploy your application to Vercel
- Explore the API using the Swagger documentation at
/docs