Optimize .env with domain-based defaults for easier deployment #14

Open
opened 2026-01-03 11:02:47 +00:00 by padreug · 0 comments
Owner

Summary

Add a base VITE_DOMAIN environment variable that automatically derives sensible defaults for all other URL-based variables. This makes deployment significantly easier - you only need to set your domain once.

Current State

Currently, deploying requires setting multiple URL variables manually:

VITE_LNBITS_BASE_URL=https://lnbits.mydomain.com
VITE_LIGHTNING_DOMAIN=mydomain.com
VITE_PICTRS_BASE_URL=https://img.mydomain.com

Proposed Solution

New Variables

# Base domain - all other URLs derive from this
VITE_DOMAIN=mydomain.com

# Protocol (defaults to true for production)
VITE_USE_HTTPS=true

Default Derivations

When VITE_DOMAIN is set, the following defaults apply:

Variable Default Value Can Override
VITE_LNBITS_BASE_URL https://lnbits.{domain}
VITE_LIGHTNING_DOMAIN {domain}
VITE_PICTRS_BASE_URL https://img.{domain}

Protocol Handling

  • VITE_USE_HTTPS=true (default) → https:// prefix
  • VITE_USE_HTTPS=falsehttp:// prefix (for local dev)
  • Explicit URLs in individual variables override the protocol setting

Example Configurations

Minimal Production Setup

VITE_DOMAIN=mydomain.com
VITE_NOSTR_RELAYS=["wss://relay.damus.io"]

Results in:

  • LNbits: https://lnbits.mydomain.com
  • Lightning Domain: mydomain.com
  • Pictrs: https://img.mydomain.com

Local Development

VITE_DOMAIN=localhost
VITE_USE_HTTPS=false
VITE_LNBITS_BASE_URL=http://localhost:5000

Custom Subdomains

VITE_DOMAIN=mydomain.com
VITE_LNBITS_BASE_URL=https://pay.mydomain.com  # Override default
VITE_PICTRS_BASE_URL=https://media.mydomain.com  # Override default

Implementation Notes

  1. Update src/lib/config.ts to implement domain-based defaults
  2. Maintain full backward compatibility - existing explicit URLs take precedence
  3. Update .env.example with the new pattern
  4. Consider adding validation warnings if conflicting values are detected

Benefits

  • Simpler deployment: One domain variable instead of 3+ URL variables
  • Less error-prone: No risk of typos across multiple similar URLs
  • Self-documenting: Clear relationship between services and domain
  • Backward compatible: Existing configs continue to work unchanged
## Summary Add a base `VITE_DOMAIN` environment variable that automatically derives sensible defaults for all other URL-based variables. This makes deployment significantly easier - you only need to set your domain once. ## Current State Currently, deploying requires setting multiple URL variables manually: ```env VITE_LNBITS_BASE_URL=https://lnbits.mydomain.com VITE_LIGHTNING_DOMAIN=mydomain.com VITE_PICTRS_BASE_URL=https://img.mydomain.com ``` ## Proposed Solution ### New Variables ```env # Base domain - all other URLs derive from this VITE_DOMAIN=mydomain.com # Protocol (defaults to true for production) VITE_USE_HTTPS=true ``` ### Default Derivations When `VITE_DOMAIN` is set, the following defaults apply: | Variable | Default Value | Can Override | |----------|---------------|--------------| | `VITE_LNBITS_BASE_URL` | `https://lnbits.{domain}` | ✅ | | `VITE_LIGHTNING_DOMAIN` | `{domain}` | ✅ | | `VITE_PICTRS_BASE_URL` | `https://img.{domain}` | ✅ | ### Protocol Handling - `VITE_USE_HTTPS=true` (default) → `https://` prefix - `VITE_USE_HTTPS=false` → `http://` prefix (for local dev) - Explicit URLs in individual variables override the protocol setting ## Example Configurations ### Minimal Production Setup ```env VITE_DOMAIN=mydomain.com VITE_NOSTR_RELAYS=["wss://relay.damus.io"] ``` Results in: - LNbits: `https://lnbits.mydomain.com` - Lightning Domain: `mydomain.com` - Pictrs: `https://img.mydomain.com` ### Local Development ```env VITE_DOMAIN=localhost VITE_USE_HTTPS=false VITE_LNBITS_BASE_URL=http://localhost:5000 ``` ### Custom Subdomains ```env VITE_DOMAIN=mydomain.com VITE_LNBITS_BASE_URL=https://pay.mydomain.com # Override default VITE_PICTRS_BASE_URL=https://media.mydomain.com # Override default ``` ## Implementation Notes 1. Update `src/lib/config.ts` to implement domain-based defaults 2. Maintain full backward compatibility - existing explicit URLs take precedence 3. Update `.env.example` with the new pattern 4. Consider adding validation warnings if conflicting values are detected ## Benefits - **Simpler deployment**: One domain variable instead of 3+ URL variables - **Less error-prone**: No risk of typos across multiple similar URLs - **Self-documenting**: Clear relationship between services and domain - **Backward compatible**: Existing configs continue to work unchanged
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: aiolabs/webapp#14
No description provided.