newOS for Developers
Configuration System
Environment-based configuration for API endpoints, media buckets, authentication, and WebSocket connections.
packages/newgraph-signals/src/config/
Overview
The config system provides environment-aware configuration that automatically selects the appropriate endpoints based on the current hostname. It supports development, staging, and production environments.
import {
newgraphBaseUrl,
mediaBucket,
websocketsServer,
authDomain,
stage
} from "newgraph-signals/config";
// Use configured endpoints
const response = await fetch(`${newgraphBaseUrl}/user/current`);
const imageUrl = `${mediaBucket}/${imageId}`;Environment Stages
The current stage is automatically determined based on the hostname.
| Stage | Hosts | Purpose |
|---|---|---|
| eu-dev | os-dev.newcoin.org | Development environment |
| eu-sit | test.newlife.io | System integration testing |
| eu-prod | os.newcoin.org, web.newos.computer, localhost | Production environment |
// stages.ts - Stage detection logic
const stages: Record<string, string> = {
"os-dev.newcoin.org": "eu-dev",
"test.newlife.io": "eu-sit",
"os.newcoin.org": "eu-prod",
"web.newos.computer": "eu-prod",
"localhost": "eu-prod",
// ...
};
export const stage = stages[currentHost];Exported Configuration
newgraphBaseUrlstringBase URL for Newgraph API requests.
mediaBucketstringCDN URL for media assets (images, videos).
websocketsServerstringWebSocket server for real-time updates.
authDomainstringDomain for authentication redirects.
stagestringCurrent environment stage (eu-dev, eu-sit, eu-prod).
Host Utilities
Functions for hostname detection, canonical host enforcement, and protocol security.
actualCurrentHostThe actual hostname from window.location.hostname
isLocalhostBoolean indicating if running on localhost (127.0.0.1, localhost, 172.20.10.2)
getCurrentHost(localhostHost: string): stringReturns the current host, with optional localhost override.
ensureCanonicalHost(hosts, stage): voidRedirects to canonical host if current host is not in the allowed list.
ensureProtocol(): voidRedirects HTTP to HTTPS (except on localhost).
replaceHost(host?: string): stringGenerates HTTPS URL with optional host replacement.
Firebase Configuration
Firebase configuration for authentication services.
type FirebaseConfig = {
apiKey: string;
authDomain: string;
projectId: string;
storageBucket: string;
messagingSenderId: string;
appId: string;
measurementId: string;
};
// Production config
firebaseConfigs["eu-prod"] = {
apiKey: "AIzaSyCp3P43sVXFH9ep1a82BkArdBr9dYXREJM",
authDomain: "newos-929cf.firebaseapp.com",
projectId: "newos-929cf",
storageBucket: "newos-929cf.firebasestorage.app",
messagingSenderId: "740227261304",
appId: "1:740227261304:web:644316dd44693d7770de8d",
measurementId: "G-3Z9RZ891SD"
};Environment Variables
The env.ts file contains hardcoded environment configuration.
| Variable | Purpose |
|---|---|
| REACT_APP_IOSDK_APP_NAME | Application name (newlife) |
| REACT_APP_IOSDK_APP_DOMAIN_* | Domain configuration per stage |
| REACT_APP_IOSDK_APP_*_HOST | Allowed hosts per stage |
| REACT_APP_IOSDK_APP_*_CANONICAL_HOSTS | Canonical redirect hosts |
| REACT_APP_PROD_FIREBASE_* | Firebase configuration |
Config Files
| File | Purpose |
|---|---|
| index.ts | Main exports, combines all configs for current stage |
| env.ts | Environment variable definitions |
| stages.ts | Host-to-stage mapping logic |
| hosts.ts | Host utilities and canonical host enforcement |
| newgraphApi.ts | API base URLs per stage |
| mediaBuckets.ts | CDN URLs for media assets |
| websocketsServers.ts | WebSocket server URLs |
| authDomains.ts | Authentication domain URLs |
| firebase.ts | Firebase configuration per stage |
Usage Patterns
API Request
import { newgraphBaseUrl } from "newgraph-signals/config";
const response = await fetch(`${newgraphBaseUrl}/mood/${id}`, {
headers: { Authorization: `Bearer ${token}` }
});Media URL Construction
import { mediaBucket } from "newgraph-signals/config";
const imageUrl = `${mediaBucket}/${post.contentUrl}`;
const thumbUrl = `${mediaBucket}/${post.thumbUrl}`;WebSocket Connection
import { websocketsServer } from "newgraph-signals/config";
const ws = new WebSocket(`${websocketsServer}?token=${token}`);