Overview
The Service Orders Management System uses Nuxt 3’s runtime configuration system to manage environment-specific settings. This allows you to configure different values for development, staging, and production environments without modifying code.Runtime Configuration
Runtime configuration is defined innuxt.config.ts and can be overridden using environment variables:
nuxt.config.ts
Public vs Private Runtime Config
Public Config
Exposed to both server and client. Accessible in browser JavaScript.
Private Config
Only available on the server. Used for API keys and secrets.
API Base URL Configuration
TheapiBaseUrl setting defines the backend API endpoint:
nuxt.config.ts
Accessing Runtime Config
Use theuseRuntimeConfig() composable to access configuration values:
Example Component
Composable or Plugin
Environment Variables
Override runtime configuration using environment variables. Nuxt automatically maps environment variables to runtime config.Naming Convention
For public runtime config:- Config key:
runtimeConfig.public.apiBaseUrl - Environment variable:
NUXT_PUBLIC_API_BASE_URL
NUXT_PUBLIC_ + uppercase key with underscores
Private runtime config uses
NUXT_ prefix without PUBLIC_.Environment-Specific Configuration
Development Environment
For local development, create a This matches the default configuration in
.env file in the project root:.env
nuxt.config.ts.Staging Environment
Create a Load staging config when building:
.env.staging file or set environment variables in your CI/CD:.env.staging
Vite Environment Variables
The application also uses Vite’sdefine option for compile-time constants:
nuxt.config.ts
What This Does
- Replaces all instances of
process.env.DEBUGwithfalseat build time - Removes debug code through dead code elimination
- Reduces bundle size in production
Environment-Specific Debug Settings
You can conditionally set debug mode based on environment:nuxt.config.ts
Vite’s
define performs compile-time replacement, so these values cannot be changed at runtime. Use runtime config for values that need to change after build.Complete Configuration Example
Here’s a comprehensive example with both public and private config:nuxt.config.ts
.env file:
.env
Best Practices
Use Environment Variables for Deployment
Never hardcode environment-specific values. Use environment variables to configure:
- API endpoints
- Feature flags
- Analytics IDs
- CDN URLs
Document Required Variables
Create a
.env.example file listing all required environment variables:.env.example
Troubleshooting
Configuration not updating after change
Configuration not updating after change
Runtime config is loaded at build time for static generation or at server start for SSR. After changing environment variables:
- Restart the dev server:
npm run dev - Rebuild for production:
npm run build - Clear
.nuxtdirectory if issues persist:rm -rf .nuxt && npm run dev
Environment variables not being recognized
Environment variables not being recognized
Ensure you’re using the correct naming convention:
- Public config:
NUXT_PUBLIC_prefix - Private config:
NUXT_prefix - Use underscores for nested keys:
NUXT_PUBLIC_API_BASE_URL
Sensitive data exposed in client bundle
Sensitive data exposed in client bundle
Check that sensitive values are in private config (not under
public):Next Steps
Building for Production
Learn how to build optimized production bundles for deployment