CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-replay

HTTP request recording and replay system for API testing

Pending
Overview
Eval results
Files

host-configuration.mddocs/

Host Configuration

Replay provides flexible host routing capabilities to handle different network scenarios, including localhost redirection, pass-through hosts, and connection dropping.

Capabilities

Localhost Configuration

Configure hosts to be treated as localhost, routing requests to 127.0.0.1 without recording or replay.

/**
 * Configure hosts to be treated as localhost
 * @param {...string} hosts - Hostnames or host patterns to treat as localhost
 * @returns {Replay} The Replay instance for chaining
 */
Replay.localhost(...hosts: string[]): Replay;

/**
 * Check if a host should be treated as localhost
 * @param {string} host - Hostname to check
 * @returns {boolean} True if host should be treated as localhost
 */
Replay.isLocalhost(host: string): boolean;

Usage Examples:

const Replay = require('replay');

// Configure localhost hosts
Replay.localhost('api.myapp.local', 'test.example.com');

// Use wildcard patterns
Replay.localhost('*.dev.local', 'api.*');

// Check if host is configured as localhost
if (Replay.isLocalhost('api.myapp.local')) {
  console.log('Host will be routed to 127.0.0.1');
}

Pass-Through Configuration

Configure hosts to bypass recording and replay, allowing direct network access.

/**
 * Configure hosts to pass through directly (bypass recording/replay)
 * @param {...string} hosts - Hostnames or host patterns to pass through
 * @returns {Replay} The Replay instance for chaining
 */
Replay.passThrough(...hosts: string[]): Replay;

/**
 * Check if a host is configured for pass-through
 * @param {string} host - Hostname to check
 * @returns {boolean} True if host should pass through
 */
Replay.isPassThrough(host: string): boolean;

Usage Examples:

const Replay = require('replay');

// Configure pass-through hosts
Replay.passThrough('s3.amazonaws.com', 'cdn.example.com');

// Use wildcard patterns
Replay.passThrough('*.googleapis.com', 'api.github.*');

// Check if host is configured for pass-through
if (Replay.isPassThrough('s3.amazonaws.com')) {
  console.log('Host will bypass replay system');
}

Drop Configuration

Configure hosts to be dropped (simulate network unavailable), useful for blocking unwanted requests.

/**
 * Configure hosts to drop connections (simulate network unavailable)
 * @param {...string} hosts - Hostnames or host patterns to drop
 * @returns {Replay} The Replay instance for chaining
 */
Replay.drop(...hosts: string[]): Replay;

/**
 * Check if a host is configured to be dropped
 * @param {string} host - Hostname to check
 * @returns {boolean} True if host should be dropped
 */
Replay.isDropped(host: string): boolean;

Usage Examples:

const Replay = require('replay');

// Drop analytics and tracking hosts
Replay.drop('www.google-analytics.com', 'rollbar.com');

// Use wildcard patterns
Replay.drop('*.doubleclick.net', 'tracking.*');

// Check if host is configured to be dropped
if (Replay.isDropped('www.google-analytics.com')) {
  console.log('Host connections will be dropped');
}

Reset Configuration

Remove hosts from all configuration lists (localhost, pass-through, and drop).

/**
 * Remove hosts from all lists (passThrough, drop, localhost)
 * @param {...string} hosts - Hostnames to reset
 * @returns {Replay} The Replay instance for chaining
 */
Replay.reset(...hosts: string[]): Replay;

Usage Examples:

const Replay = require('replay');

// Configure various hosts
Replay.localhost('api.local')
       .passThrough('cdn.example.com')
       .drop('tracker.example.com');

// Reset specific hosts
Replay.reset('api.local', 'cdn.example.com');

// Reset all configured hosts
Replay.reset('api.local', 'cdn.example.com', 'tracker.example.com');

Host Pattern Matching

All host configuration methods support flexible pattern matching:

Exact Match

Replay.localhost('api.example.com');
// Matches exactly: api.example.com

Wildcard Subdomain

Replay.passThrough('*.example.com');
// Matches: api.example.com, cdn.example.com, www.example.com
// Does not match: example.com, test.api.example.com

Reverse Wildcard

Replay.drop('api.*');
// Matches: api.example.com, api.test.com, api.local
// Does not match: test.api.example.com

Multiple Patterns

// Configure multiple patterns at once
Replay.localhost('localhost', '127.0.0.1', '::1', '*.local');

Configuration Priority

When a host matches multiple configurations, the priority is:

  1. Localhost: Highest priority - routes to 127.0.0.1
  2. Drop: Second priority - drops connection
  3. Pass-through: Third priority - bypasses replay
  4. Default behavior: Follows current mode settings

Usage Examples:

const Replay = require('replay');

// This host will be treated as localhost (highest priority)
Replay.localhost('api.example.com')
       .drop('api.example.com')
       .passThrough('api.example.com');

// Check priorities
console.log(Replay.isLocalhost('api.example.com'));   // true
console.log(Replay.isDropped('api.example.com'));     // true
console.log(Replay.isPassThrough('api.example.com')); // true

// But actual behavior will be localhost routing

Chaining Support

All configuration methods return the Replay instance for method chaining:

const Replay = require('replay');

// Chain multiple configuration calls
Replay
  .localhost('*.local')
  .passThrough('s3.amazonaws.com', '*.googleapis.com')
  .drop('*.doubleclick.net', 'www.google-analytics.com')
  .reset('old.example.com');

Install with Tessl CLI

npx tessl i tessl/npm-replay

docs

fixture-management.md

host-configuration.md

index.md

mode-management.md

proxy-system.md

tile.json