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 →
Strategy | Best For | Use Case | Predictability | Infrastructure Control |
---|---|---|---|---|
Static | Single gateway | Development, specific gateway requirements | Maximum | High |
Fastest Ping | Real-time applications | Performance-critical apps, gaming | Medium | Low |
Preferred + Fallback | Dedicated infrastructure | CDN with origin fallback, enterprise gateways | High | Maximum |
Round Robin | Load balancing | Even distribution across known gateways | High | High |
Random | Simple distribution | Basic load spreading, testing | Low | Medium |
← Swipe to see more →
How It Works
The strategy always returns the configured gateway, ignoring any provided gateway lists:
- Configure Gateway: Set a single gateway URL during initialization
- Ignore Provided Gateways: Any gateways from providers are ignored
- Return Static Gateway: Always return the same configured gateway
- 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
Parameter | Type | Default | Description |
---|---|---|---|
gateway | string | required | The gateway URL to always use |
logger | Logger | defaultLogger | Optional 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
- Use for Development: Great for local development and testing
- Ensure Gateway Reliability: Make sure your static gateway is highly available
- Monitor Performance: Track the performance of your single gateway
- Plan for Failures: Consider fallback strategies for production use
- 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.