Skip to main content

Environment Basics

Environments in KnoxCall allow you to manage different configurations (dev, staging, production) for the same route without duplicating everything.

What is an Environment?

An environment is a configuration context that determines which settings to use for a route. Think of it as a profile or mode.

Real-World Analogy

Imagine a light switch with multiple modes:
  • “Day” mode → Bright lights, full power
  • “Night” mode → Dim lights, low power
  • “Movie” mode → Colored lights, ambient
Same switch, different settings based on the mode. Environments work the same way:
  • Production → Real API keys, production database
  • Staging → Test API keys, staging database
  • Development → Mock data, local server

Why Use Environments?

The Problem Without Environments

Without environments, you’d need separate routes for each stage:
Issues:
  • Duplicate routes to maintain
  • Easy to misconfigure
  • Hard to keep in sync
  • Route names get messy

The Solution With Environments

With environments, you have one route with different configs:
Benefits:
  • Single route to maintain
  • Consistent naming
  • Easy to switch between environments
  • Clear separation of configs

How Environments Work

The Base + Override System

KnoxCall uses a base + override system:
  1. Base environment - Default configuration
  2. Override environments - Customize specific settings
Example:
How it works:
  • If override = null or empty → Use base value
  • If override = specific value → Use override value
  • Changes to base automatically affect overrides (unless overridden)
  • Inheritance is single-level: each override falls back to the base (production) config, never to another override. There is no override-to-override chaining.

Default Environments

KnoxCall creates one default environment for every tenant:

Production (Base Environment)

  • Name: production
  • Type: Base
  • Purpose: Default configuration
  • Usage: If no environment specified, this is used
When you create a route, you’re actually configuring the production environment.

Common Environment Setup

Typical 3-Environment Setup

Most teams use three environments:

1. Development

  • Purpose: Local development and testing
  • Target: http://localhost:3000 or sandbox APIs
  • Secrets: Test/fake API keys
  • Clients: Developer laptops (dynamic IPs)
  • Example:

2. Staging

  • Purpose: Pre-production testing
  • Target: Staging servers
  • Secrets: Staging API keys (real-ish data)
  • Clients: Staging servers + QA team
  • Example:

3. Production

  • Purpose: Live customer traffic
  • Target: Production servers
  • Secrets: Production API keys (real data!)
  • Clients: Production servers only
  • Example:

Using Environments in Requests

Specify Environment with Header

To use a specific environment, add the header:

No Header = Base Environment

If you don’t specify x-knoxcall-environment, KnoxCall uses the base environment (usually production).

What Can Be Overridden?

You can override almost everything per environment:

✅ Can Override

❌ Cannot Override


Real-World Examples

Example 1: Stripe API Route

Scenario: Process payments via Stripe in all environments. Setup:
Result:
  • Production charges real cards with prod key
  • Staging/dev use test keys (no real charges)
  • Different client authorization per environment

Example 2: Database API

Scenario: Query user database across environments. Setup:
Result:
  • Each environment hits a completely different database
  • Developers work with local data
  • Staging has realistic test data
  • Production has real customer data

Example 3: Third-Party Webhooks

Scenario: Receive webhooks from Shopify. Setup:
Result:
  • Production webhooks go to production backend
  • Staging webhooks go to staging
  • Dev webhooks tunnel to developer’s localhost via ngrok

NULL Values = Inherit

This is a key concept: NULL or empty values inherit from the base.

Example

Result:
  • Target URL: https://api.production.com (inherited)
  • Header: Bearer staging_key (overridden)

Best Practices

✅ Do

1. Use descriptive environment names
2. Separate secrets per environment
3. Different client authorization
4. Test in staging first
5. Document environment purpose

❌ Don’t

1. Don’t use production secrets in dev
2. Don’t allow dev IPs in production
3. Don’t mix environments
4. Don’t skip staging
5. Don’t use generic names

When to Create New Environments

Create New Environments When:

  1. Different target systems
    • Production API vs staging API vs local dev
  2. Different credentials
    • Production keys vs test keys
  3. Different authorization
    • Production servers vs developer laptops
  4. Different teams
    • QA environment separate from dev
  5. Different regions
    • US environment vs EU environment

Don’t Create Environments For:

  1. Different features - Use different routes instead
  2. Different customers - Use route parameters or headers
  3. Different versions - Use API versioning in URLs
  4. Temporary testing - Use staging environment

Environment Workflows

Development Workflow

Environment Promotion


Troubleshooting

Environment Not Found

Error:
Solution:
  1. Go to ResourcesEnvironments
  2. Check if “staging” exists
  3. Create it if missing
  4. Verify spelling (case-sensitive)

Using Wrong Environment

Symptom: Request goes to wrong backend. Solution:
  1. Check x-knoxcall-environment header value
  2. Verify environment name spelling
  3. Check which environment your route is configured for

Override Not Working

Symptom: Still using base configuration despite override. Cause: Override value is null (inheritance). Solution:
  1. Edit route → Environment tab
  2. Set specific value (not null)
  3. Save changes

Quick Reference


Next Steps

Environment Workflows

Advanced environment patterns

Rate Limiting

Per-environment rate limits

First Environment

Create your first environment

Managing Secrets

Environment-specific secrets

Key Takeaway: Environments let you manage dev, staging, and production with one route instead of three. Override only what’s different, inherit the rest!