or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

fixture-management.mdhost-configuration.mdindex.mdmode-management.mdproxy-system.md

host-configuration.mddocs/

0

# Host Configuration

1

2

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

3

4

## Capabilities

5

6

### Localhost Configuration

7

8

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

9

10

```javascript { .api }

11

/**

12

* Configure hosts to be treated as localhost

13

* @param {...string} hosts - Hostnames or host patterns to treat as localhost

14

* @returns {Replay} The Replay instance for chaining

15

*/

16

Replay.localhost(...hosts: string[]): Replay;

17

18

/**

19

* Check if a host should be treated as localhost

20

* @param {string} host - Hostname to check

21

* @returns {boolean} True if host should be treated as localhost

22

*/

23

Replay.isLocalhost(host: string): boolean;

24

```

25

26

**Usage Examples:**

27

28

```javascript

29

const Replay = require('replay');

30

31

// Configure localhost hosts

32

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

33

34

// Use wildcard patterns

35

Replay.localhost('*.dev.local', 'api.*');

36

37

// Check if host is configured as localhost

38

if (Replay.isLocalhost('api.myapp.local')) {

39

console.log('Host will be routed to 127.0.0.1');

40

}

41

```

42

43

### Pass-Through Configuration

44

45

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

46

47

```javascript { .api }

48

/**

49

* Configure hosts to pass through directly (bypass recording/replay)

50

* @param {...string} hosts - Hostnames or host patterns to pass through

51

* @returns {Replay} The Replay instance for chaining

52

*/

53

Replay.passThrough(...hosts: string[]): Replay;

54

55

/**

56

* Check if a host is configured for pass-through

57

* @param {string} host - Hostname to check

58

* @returns {boolean} True if host should pass through

59

*/

60

Replay.isPassThrough(host: string): boolean;

61

```

62

63

**Usage Examples:**

64

65

```javascript

66

const Replay = require('replay');

67

68

// Configure pass-through hosts

69

Replay.passThrough('s3.amazonaws.com', 'cdn.example.com');

70

71

// Use wildcard patterns

72

Replay.passThrough('*.googleapis.com', 'api.github.*');

73

74

// Check if host is configured for pass-through

75

if (Replay.isPassThrough('s3.amazonaws.com')) {

76

console.log('Host will bypass replay system');

77

}

78

```

79

80

### Drop Configuration

81

82

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

83

84

```javascript { .api }

85

/**

86

* Configure hosts to drop connections (simulate network unavailable)

87

* @param {...string} hosts - Hostnames or host patterns to drop

88

* @returns {Replay} The Replay instance for chaining

89

*/

90

Replay.drop(...hosts: string[]): Replay;

91

92

/**

93

* Check if a host is configured to be dropped

94

* @param {string} host - Hostname to check

95

* @returns {boolean} True if host should be dropped

96

*/

97

Replay.isDropped(host: string): boolean;

98

```

99

100

**Usage Examples:**

101

102

```javascript

103

const Replay = require('replay');

104

105

// Drop analytics and tracking hosts

106

Replay.drop('www.google-analytics.com', 'rollbar.com');

107

108

// Use wildcard patterns

109

Replay.drop('*.doubleclick.net', 'tracking.*');

110

111

// Check if host is configured to be dropped

112

if (Replay.isDropped('www.google-analytics.com')) {

113

console.log('Host connections will be dropped');

114

}

115

```

116

117

### Reset Configuration

118

119

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

120

121

```javascript { .api }

122

/**

123

* Remove hosts from all lists (passThrough, drop, localhost)

124

* @param {...string} hosts - Hostnames to reset

125

* @returns {Replay} The Replay instance for chaining

126

*/

127

Replay.reset(...hosts: string[]): Replay;

128

```

129

130

**Usage Examples:**

131

132

```javascript

133

const Replay = require('replay');

134

135

// Configure various hosts

136

Replay.localhost('api.local')

137

.passThrough('cdn.example.com')

138

.drop('tracker.example.com');

139

140

// Reset specific hosts

141

Replay.reset('api.local', 'cdn.example.com');

142

143

// Reset all configured hosts

144

Replay.reset('api.local', 'cdn.example.com', 'tracker.example.com');

145

```

146

147

## Host Pattern Matching

148

149

All host configuration methods support flexible pattern matching:

150

151

### Exact Match

152

```javascript

153

Replay.localhost('api.example.com');

154

// Matches exactly: api.example.com

155

```

156

157

### Wildcard Subdomain

158

```javascript

159

Replay.passThrough('*.example.com');

160

// Matches: api.example.com, cdn.example.com, www.example.com

161

// Does not match: example.com, test.api.example.com

162

```

163

164

### Reverse Wildcard

165

```javascript

166

Replay.drop('api.*');

167

// Matches: api.example.com, api.test.com, api.local

168

// Does not match: test.api.example.com

169

```

170

171

### Multiple Patterns

172

```javascript

173

// Configure multiple patterns at once

174

Replay.localhost('localhost', '127.0.0.1', '::1', '*.local');

175

```

176

177

## Configuration Priority

178

179

When a host matches multiple configurations, the priority is:

180

181

1. **Localhost**: Highest priority - routes to 127.0.0.1

182

2. **Drop**: Second priority - drops connection

183

3. **Pass-through**: Third priority - bypasses replay

184

4. **Default behavior**: Follows current mode settings

185

186

**Usage Examples:**

187

188

```javascript

189

const Replay = require('replay');

190

191

// This host will be treated as localhost (highest priority)

192

Replay.localhost('api.example.com')

193

.drop('api.example.com')

194

.passThrough('api.example.com');

195

196

// Check priorities

197

console.log(Replay.isLocalhost('api.example.com')); // true

198

console.log(Replay.isDropped('api.example.com')); // true

199

console.log(Replay.isPassThrough('api.example.com')); // true

200

201

// But actual behavior will be localhost routing

202

```

203

204

## Chaining Support

205

206

All configuration methods return the Replay instance for method chaining:

207

208

```javascript

209

const Replay = require('replay');

210

211

// Chain multiple configuration calls

212

Replay

213

.localhost('*.local')

214

.passThrough('s3.amazonaws.com', '*.googleapis.com')

215

.drop('*.doubleclick.net', 'www.google-analytics.com')

216

.reset('old.example.com');

217

```