Skip to content

Commit 685a097

Browse files
committed
Merge pull request #10 from indexzero/host
Use host in stead of IP and fix logic
2 parents 348c65e + 3fca738 commit 685a097

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

index.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ module.exports = function createServers(options, listening) {
4646
var handler = options.handler,
4747
log = options.log || function () { },
4848
errors = {},
49-
servers = {},
50-
errState;
49+
servers = {};
5150

5251
//
5352
// ### function onListen(type, err, server)
@@ -72,7 +71,7 @@ module.exports = function createServers(options, listening) {
7271
return listening(errs.create({
7372
message: (errors.https || errors.http).message,
7473
https: errors.https,
75-
http: errors.http,
74+
http: errors.http
7675
}), servers);
7776
}
7877

@@ -101,12 +100,11 @@ module.exports = function createServers(options, listening) {
101100

102101
var server = http.createServer(options.http.handler || handler),
103102
port = options.http.port || 80,
104-
args,
105-
ip;
103+
args;
106104

107105
args = [server, port];
108-
if (ip === options.http.ip) {
109-
args.push(ip);
106+
if (options.http.host) {
107+
args.push(options.http.host);
110108
}
111109

112110
log('http | try listen ' + port);
@@ -160,7 +158,7 @@ module.exports = function createServers(options, listening) {
160158
// https://certsimple.com/blog/a-plus-node-js-ssl
161159
//
162160
ciphers: ssl.ciphers,
163-
honorCipherOrder: ssl.honorCipherOrder === false ? false : true,
161+
honorCipherOrder: !!ssl.honorCipherOrder,
164162
//
165163
// Optionally support SNI-based SSL.
166164
//
@@ -174,8 +172,8 @@ module.exports = function createServers(options, listening) {
174172
}, ssl.handler || handler);
175173

176174
args = [server, port];
177-
if (ip === options.https.ip) {
178-
args.push(ip);
175+
if (options.https.host) {
176+
args.push(options.https.host);
179177
}
180178

181179
args.push(function listener(err) { onListen('https', err, this); });

test/create-servers-test.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ test('http && https with different handlers', function (t) {
128128
t.plan(3);
129129
createServers({
130130
log: console.log,
131-
http: "9876",
131+
http: '9876',
132132
handler: fend
133133
}, function (err, servers) {
134134
console.dir(err);
@@ -138,4 +138,24 @@ test('http && https with different handlers', function (t) {
138138
servers.http.close();
139139
});
140140
});
141+
142+
test('host can be provided to the server', function (t) {
143+
t.plan(4);
144+
createServers({
145+
log: console.log,
146+
http: {
147+
port: 9877,
148+
host: '127.0.0.1'
149+
},
150+
handler: fend
151+
}, function (err, servers) {
152+
console.dir(err);
153+
t.error(err);
154+
t.equals(typeof servers, 'object');
155+
t.equals(typeof servers.http, 'object');
156+
t.equals(servers.http.address().address, '127.0.0.1');
157+
158+
servers.http.close();
159+
});
160+
});
141161
});

0 commit comments

Comments
 (0)