Skip to content

Commit 9077551

Browse files
committed
Support --loopback 127.0.0.1
#292 (comment)
1 parent c33f022 commit 9077551

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,7 @@ Usage: `airtap [options] <files>`. Supports multiple `files`. They can be paths
270270
--live keep browsers open to allow repeated test runs
271271
-p, --preset <preset> select a configuration preset
272272
-s, --server <script> path to script that runs a support server
273-
--loopback <hostname> custom hostname for tunneling, default
274-
airtap.local
273+
--loopback <hostname> custom hostname that equals or resolves to 127.0.0.1
275274
--verbose enable airtap debug output
276275
--silly enable all debug output
277276
-h, --help display help for command

bin/airtap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ program
3030
.option('--live', 'keep browsers open to allow repeated test runs')
3131
.option('-p, --preset <preset>', 'select a configuration preset')
3232
.option('-s, --server <script>', 'path to script that runs a support server')
33-
.option('--loopback <hostname>', 'custom hostname for tunneling, default airtap.local')
33+
.option('--loopback <hostname>', 'custom hostname that equals or resolves to 127.0.0.1')
3434
.option('--verbose', 'enable airtap debug output')
3535
.option('--silly', 'enable all debug output')
3636

lib/proxy-server.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const http = require('http')
1313
const kLoopback = Symbol('kLoopback')
1414
const kServer = Symbol('kServer')
1515
const kUrl = Symbol('kUrl')
16+
const ip = '127.0.0.1'
1617

1718
module.exports = class ProxyServer extends Nanoresource {
1819
constructor (manifest, cid, opts) {
@@ -21,7 +22,7 @@ module.exports = class ProxyServer extends Nanoresource {
2122
this.port = null
2223
this.url = null
2324

24-
this[kLoopback] = manifest.wants.loopback ? opts.loopback || 'airtap.local' : 'localhost'
25+
this[kLoopback] = opts.loopback || (manifest.wants.loopback ? 'airtap.local' : 'localhost')
2526
this[kServer] = http.createServer()
2627

2728
const self = this
@@ -56,8 +57,8 @@ module.exports = class ProxyServer extends Nanoresource {
5657
}
5758

5859
_open (callback) {
59-
lookup(this[kLoopback], { family: 4 }, (err, address) => {
60-
if (err ? err.code === 'ENOTFOUND' : address !== '127.0.0.1') {
60+
maybeLookup(this[kLoopback], { family: 4 }, (err, address) => {
61+
if (err ? err.code === 'ENOTFOUND' : address !== ip) {
6162
return callback(new LoopbackError(this[kLoopback]))
6263
} else if (err) {
6364
return callback(transient(err))
@@ -84,9 +85,17 @@ module.exports = class ProxyServer extends Nanoresource {
8485
}
8586
}
8687

88+
function maybeLookup (hostname, opts, callback) {
89+
if (hostname === ip) {
90+
process.nextTick(callback, null, ip)
91+
} else {
92+
lookup(hostname, opts, callback)
93+
}
94+
}
95+
8796
class LoopbackError extends Error {
8897
constructor (loopback) {
89-
super(`Hostname '${loopback}' must resolve to 127.0.0.1. Please add an entry to your hosts file.`)
98+
super(`Hostname '${loopback}' must resolve to ${ip}. Please add an entry to your hosts file.`)
9099

91100
Object.defineProperty(this, 'name', { value: 'LoopbackError' })
92101
Object.defineProperty(this, 'expected', { value: true })

0 commit comments

Comments
 (0)