Overview
MKing Admin uses Vite for build tooling and environment variable management. All environment variables must be prefixed withVITE_ to be exposed to the application.
Environment Variables
Environment variables are defined in.env files at the root of your project. Create a .env file based on the .env.example template.
API Configuration
The base URL for the API backend. This is used by all service modules to construct API endpoints.Development example:Production example:
The application environment mode. Used to determine which configuration set to use.Possible values:
develop- Development environmentproduction- Production environment
Application URLs
The testing/staging URL for the Garantia application.
The production URL for the Garantia application.
Optional base URL for serving static assets like employee images.
Environment File Setup
Development Environment
Create a.env file in your project root:
Production Environment
For production deployments, update your environment variables:Accessing Environment Variables
Environment variables are accessed using Vite’simport.meta.env object:
Example Usage in Services
All API services use theVITE_BASE_URL environment variable to construct endpoints:
src/services/admin.service.tsx
Development Server Configuration
The development server is configured invite.config.ts:
The development server runs on port 5000 by default and includes an API proxy for local development.
Best Practices
- Always prefix with VITE_: Only environment variables prefixed with
VITE_are exposed to the client-side code - Use .env.example: Maintain a
.env.examplefile with all required variables (without sensitive values) - Environment-specific files: Create
.env.developmentand.env.productionfor environment-specific configurations - Type safety: Consider creating a typed wrapper around
import.meta.envfor better TypeScript support
Troubleshooting
Variables Not Loading
If environment variables aren’t working:- Ensure the variable name starts with
VITE_ - Restart the development server after changing
.envfiles - Check that the
.envfile is in the project root - Verify the variable is not commented out
API Connection Errors
If you’re experiencing API connection issues:- Verify
VITE_BASE_URLpoints to the correct backend - Check that the backend server is running
- Ensure CORS is properly configured on the backend
- Review the proxy configuration in
vite.config.ts