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.

StageHostsPurpose
eu-devos-dev.newcoin.orgDevelopment environment
eu-sittest.newlife.ioSystem integration testing
eu-prodos.newcoin.org, web.newos.computer, localhostProduction 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

newgraphBaseUrlstring

Base URL for Newgraph API requests.

eu-dev: https://api-eu-dev.newgra.ph/v1
eu-sit: https://api-eu-sit.newlife.io/creator
eu-prod: https://api.newgra.ph/v1
mediaBucketstring

CDN URL for media assets (images, videos).

All stages: https://cdn.newgra.ph
websocketsServerstring

WebSocket server for real-time updates.

eu-dev: wss://wsapi-eu-dev.newgra.ph/v1
eu-sit: wss://wsapi-eu-sit.newlife.io/creator
eu-prod: wss://wsapi.newgra.ph/v1
authDomainstring

Domain for authentication redirects.

All stages: https://os.newcoin.org
stagestring

Current environment stage (eu-dev, eu-sit, eu-prod).

Host Utilities

Functions for hostname detection, canonical host enforcement, and protocol security.

actualCurrentHost

The actual hostname from window.location.hostname

isLocalhost

Boolean indicating if running on localhost (127.0.0.1, localhost, 172.20.10.2)

getCurrentHost(localhostHost: string): string

Returns the current host, with optional localhost override.

ensureCanonicalHost(hosts, stage): void

Redirects to canonical host if current host is not in the allowed list.

ensureProtocol(): void

Redirects HTTP to HTTPS (except on localhost).

replaceHost(host?: string): string

Generates 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.

VariablePurpose
REACT_APP_IOSDK_APP_NAMEApplication name (newlife)
REACT_APP_IOSDK_APP_DOMAIN_*Domain configuration per stage
REACT_APP_IOSDK_APP_*_HOSTAllowed hosts per stage
REACT_APP_IOSDK_APP_*_CANONICAL_HOSTSCanonical redirect hosts
REACT_APP_PROD_FIREBASE_*Firebase configuration

Config Files

FilePurpose
index.tsMain exports, combines all configs for current stage
env.tsEnvironment variable definitions
stages.tsHost-to-stage mapping logic
hosts.tsHost utilities and canonical host enforcement
newgraphApi.tsAPI base URLs per stage
mediaBuckets.tsCDN URLs for media assets
websocketsServers.tsWebSocket server URLs
authDomains.tsAuthentication domain URLs
firebase.tsFirebase 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}`);