StaticRoutingStrategy

Overview

The StaticRoutingStrategy is the simplest routing strategy that always returns a single, pre-configured gateway URL. This strategy ignores any gateways provided by the GatewaysProvider and is useful for scenarios where you want to force all requests to use a specific gateway.

Routing Strategy Comparison

← Swipe to see more →
StrategyBest ForUse CasePredictabilityInfrastructure Control
StaticSingle gatewayDevelopment, specific gateway requirementsMaximumHigh
Fastest PingReal-time applicationsPerformance-critical apps, gamingMediumLow
Preferred + FallbackDedicated infrastructureCDN with origin fallback, enterprise gatewaysHighMaximum
Round RobinLoad balancingEven distribution across known gatewaysHighHigh
RandomSimple distributionBasic load spreading, testingLowMedium
← Swipe to see more →

How It Works

The strategy always returns the configured gateway, ignoring any provided gateway lists:

  1. Configure Gateway: Set a single gateway URL during initialization
  2. Ignore Provided Gateways: Any gateways from providers are ignored
  3. Return Static Gateway: Always return the same configured gateway
  4. Log Warnings: Warn when provided gateways are ignored

Configuration

Basic Usage

import { StaticRoutingStrategy } from '@ar.io/wayfinder-core'

const strategy = new StaticRoutingStrategy({
  gateway: 'https://arweave.net',
})

With Custom Gateway

const strategy = new StaticRoutingStrategy({
  gateway: 'https://my-custom-gateway.com',
})

Parameters

ParameterTypeDefaultDescription
gatewaystringrequiredThe gateway URL to always use
loggerLoggerdefaultLoggerOptional logger instance

Integration with Wayfinder

import { Wayfinder, StaticRoutingStrategy } from '@ar.io/wayfinder-core'

const wayfinder = new Wayfinder({
  routingSettings: {
    strategy: new StaticRoutingStrategy({
      gateway: 'https://arweave.net',
    }),
  },
})

Use Cases

Development Environment

Perfect for local development or testing against a specific gateway.

const devStrategy = new StaticRoutingStrategy({
  gateway: 'http://localhost:1984',
})

Dedicated Gateway

Ideal when you need to ensure all requests use your organization's specific gateway.

const dedicatedStrategy = new StaticRoutingStrategy({
  gateway: 'https://gateway.mycompany.com',
})

Compliance Requirements

Useful when compliance requires all requests to go through an approved gateway.

const complianceStrategy = new StaticRoutingStrategy({
  gateway: 'https://approved-gateway.enterprise.com',
})

Best Practices

  1. Use for Development: Great for local development and testing
  2. Ensure Gateway Reliability: Make sure your static gateway is highly available
  3. Monitor Performance: Track the performance of your single gateway
  4. Plan for Failures: Consider fallback strategies for production use
  5. Document Gateway Choice: Clearly document why a static gateway is needed

The StaticRoutingStrategy is ideal for development, testing, or scenarios where you need complete control over which gateway is used.

Was this page helpful?