Guides

Environment & Configuration

How the BizTech app handles environments, configuration, and stage-switching across frontend and backend.


Environments

EnvironmentFrontend URLBackend URLDatabase SuffixPurpose
Locallocalhost:3000localhost:4000"" (empty)Development
Devdev.app.ubcbiztech.comapi-dev.ubcbiztech.com"" (empty)Feature testing
Productionapp.ubcbiztech.comapi.ubcbiztech.com"PROD"Live for users

Dev and Production Share Nothing

The PROD suffix means production tables are completely separate from dev. But dev and staging share the same tables (both have empty suffix), so be careful with test data.


Frontend Configuration

The Stage Variable

The single most important config value is NEXT_PUBLIC_REACT_APP_STAGE, defined in src/lib/dbconfig.ts:

const defined_stage = process.env.NEXT_PUBLIC_REACT_APP_STAGE

// Determines which API URL to use:
// "local"      → http://localhost:4000
// "production" → https://api.ubcbiztech.com
// anything else → https://api-dev.ubcbiztech.com

This variable controls:

  • Which backend API the frontend talks to
  • Which WebSocket URLs are used
  • Which Interactions API is used

All Frontend Config Values

Exported from src/lib/dbconfig.ts:

ExportDescription
API_URLBackend API base URL (varies by stage)
CLIENT_URLFrontend URL (varies by stage)
WS_URLWebSocket URL for live wall
INTERACTIONS_URLWebSocket URL for interactions/stickers
EVENT_IDCurrent active event ID constant

Setting the Stage Locally

Create a .env.local file in the bt-web-v2 root:

NEXT_PUBLIC_REACT_APP_STAGE=local

This points the frontend at localhost:4000. To point at the dev API instead, omit this variable or set it to anything other than "local" or "production".


Backend Configuration

Config Files

The backend reads config from JSON files based on the STAGE environment variable:

FileWhen Used
config.dev.jsonSTAGE=dev or STAGE=""
config.staging.jsonSTAGE=staging
config.prod.jsonSTAGE=prod

The readConfigFile() function in handler.js loads the correct config at startup.

Key Config Values

Each config file contains:

{
  "AWS_REGION": "us-west-2",
  "ENVIRONMENT": "",
  "COGNITO_USER_POOL_ID": "us-west-2_w0R176hhp",
  "SENDGRID_KEY": "...",
  "STRIPE_KEY": "...",
  "ALGOLIA_APP_ID": "...",
  "ALGOLIA_API_KEY": "...",
  "SNS_TOPIC_ARN": "..."
}

The ENVIRONMENT value (empty string for dev, "PROD" for production) is appended to all DynamoDB table names by lib/db.js. See Database Guide for details.

Serverless Common Config

serverless.common.yml contains shared configuration that all services inherit:

  • AWS region (us-west-2)
  • Runtime (nodejs20.x)
  • IAM permissions
  • Environment variable injection (from the stage-specific config file)
  • Cognito authorizer reference

Individual service serverless.yml files reference it with ${file(../../serverless.common.yml):custom}.


Local Development Setup

Frontend

cd bt-web-v2
npm install
echo "NEXT_PUBLIC_REACT_APP_STAGE=local" > .env.local
npm run dev    # Starts on port 3000

Backend

cd serverless-biztechapp-1
npm install
npm run start  # Starts all services via handler.js

This starts:

  • An Express proxy on port 4000 that routes requests to individual services
  • Each service on its own port starting from 4001 (defined in sls-multi-gateways.yml)
  • DynamoDB Local (if configured)

Connecting Frontend to Backend

With NEXT_PUBLIC_REACT_APP_STAGE=local, the frontend makes API calls to http://localhost:4000, which is the Express proxy that routes to the correct service.


Previous
Tracing a Feature