Skip to main content

UI Environment Variables

Nar generates VITE_ environment variables available to your React code at build time via import.meta.env.

All JSON values are converted to strings: arrays become comma-separated, booleans become "true" or "false", and nulls become empty strings.


Variables Nar Provides

VariableExampleDescription
VITE_{SERVICE}_SERVICE_URLhttps://auth.us-east-1.dev.ral.narambu.comURL of each service defined in services.lambda[].
VITE_HOME_URLhttps://daw8sipu4p6qe.cloudfront.netThe CloudFront distribution domain.

With a custom domain configured in domains.json, VITE_{SERVICE}_SERVICE_URL values follow this pattern:

https://{service}.{region}.{site}.{vertical}.{domain}

Without a custom domain, they contain the raw API Gateway endpoint URL.

Any values you define in nn_env.json are also injected, automatically prefixed with VITE_.


nn_env.json — UI Config

{vertical}/ui_config/nn_env.json defines additional environment variables for the UI.

Example:

{
"name": "myapp",
"FEATURE_FLAGS": "dark_mode,notifications"
}

This produces:

VITE_name=myapp
VITE_FEATURE_FLAGS=dark_mode,notifications

Merge Priority

PrioritySourceDescription
1 (highest){vertical}/ui_config/nn_env.jsonUI config
2 (lowest)Nar-providedService URLs and CloudFront domain

Accessing Variables in React

Use import.meta.env to access any VITE_ variable:

const authUrl = import.meta.env.VITE_AUTH_SERVICE_URL;
const appName = import.meta.env.VITE_name;