Expose hostname parameter of tiny-lr
This commit is contained in:
parent
f52e5ec726
commit
0acd00f8ca
@ -26,8 +26,11 @@ module.exports = function(grunt) {
|
|||||||
} else {
|
} else {
|
||||||
options = _.defaults(options, defaults);
|
options = _.defaults(options, defaults);
|
||||||
}
|
}
|
||||||
if (servers[options.port]) {
|
|
||||||
this.server = servers[options.port];
|
var host = (options.hostname || '') + ':' + options.port;
|
||||||
|
|
||||||
|
if (servers[host]) {
|
||||||
|
this.server = servers[host];
|
||||||
} else {
|
} else {
|
||||||
this.server = tinylr(options);
|
this.server = tinylr(options);
|
||||||
this.server.server.removeAllListeners('error');
|
this.server.server.removeAllListeners('error');
|
||||||
@ -39,11 +42,11 @@ module.exports = function(grunt) {
|
|||||||
}
|
}
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
this.server.listen(options.port, function(err) {
|
this.server.listen(options.port, options.hostname, function (err) {
|
||||||
if (err) { return grunt.fatal(err); }
|
if (err) { return grunt.fatal(err); }
|
||||||
grunt.log.verbose.writeln('Live reload server started on port: ' + options.port);
|
grunt.log.verbose.writeln('Live reload server started on ' + host);
|
||||||
});
|
});
|
||||||
servers[options.port] = this.server;
|
servers[host] = this.server;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
test/fixtures/livereload/Gruntfile.js
vendored
3
test/fixtures/livereload/Gruntfile.js
vendored
@ -12,11 +12,12 @@ module.exports = function(grunt) {
|
|||||||
files: ['lib/*.js'],
|
files: ['lib/*.js'],
|
||||||
tasks: ['before'],
|
tasks: ['before'],
|
||||||
},
|
},
|
||||||
customport: {
|
customhost: {
|
||||||
files: ['lib/*.js'],
|
files: ['lib/*.js'],
|
||||||
tasks: ['before'],
|
tasks: ['before'],
|
||||||
options: {
|
options: {
|
||||||
livereload: {
|
livereload: {
|
||||||
|
hostname: 'localhost',
|
||||||
port: 8675,
|
port: 8675,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -56,18 +56,18 @@ exports.livereload = {
|
|||||||
result = helper.unixify(result);
|
result = helper.unixify(result);
|
||||||
helper.verboseLog(result);
|
helper.verboseLog(result);
|
||||||
test.ok(result.indexOf('I ran before livereload.') !== -1, 'task should have ran before live reload.');
|
test.ok(result.indexOf('I ran before livereload.') !== -1, 'task should have ran before live reload.');
|
||||||
test.ok(result.indexOf('Live reload server started on port: 35729') !== -1, 'live reload server should have been started on port 35729.');
|
test.ok(result.indexOf('Live reload server started on :35729') !== -1, 'live reload server should have been started on port 35729.');
|
||||||
test.ok(result.indexOf('Live reloading lib/one.js...') !== -1, 'live reload should have triggered on lib/one.js');
|
test.ok(result.indexOf('Live reloading lib/one.js...') !== -1, 'live reload should have triggered on lib/one.js');
|
||||||
resultData = JSON.parse(resultData);
|
resultData = JSON.parse(resultData);
|
||||||
test.equal(resultData.tinylr, 'Welcome', 'tinylr server should have welcomed you.');
|
test.equal(resultData.tinylr, 'Welcome', 'tinylr server should have welcomed you.');
|
||||||
test.done();
|
test.done();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
customport: function(test) {
|
customhost: function(test) {
|
||||||
test.expect(4);
|
test.expect(4);
|
||||||
var resultData = '';
|
var resultData = '';
|
||||||
var cwd = path.resolve(fixtures, 'livereload');
|
var cwd = path.resolve(fixtures, 'livereload');
|
||||||
var assertWatch = helper.assertTask(['watch:customport', '-v'], {cwd: cwd});
|
var assertWatch = helper.assertTask(['watch:customhost', '-v'], {cwd: cwd});
|
||||||
assertWatch([function() {
|
assertWatch([function() {
|
||||||
request(8675, function(data) {
|
request(8675, function(data) {
|
||||||
resultData += data;
|
resultData += data;
|
||||||
@ -77,7 +77,7 @@ exports.livereload = {
|
|||||||
result = helper.unixify(result);
|
result = helper.unixify(result);
|
||||||
helper.verboseLog(result);
|
helper.verboseLog(result);
|
||||||
test.ok(result.indexOf('I ran before livereload.') !== -1, 'task should have ran before live reload.');
|
test.ok(result.indexOf('I ran before livereload.') !== -1, 'task should have ran before live reload.');
|
||||||
test.ok(result.indexOf('Live reload server started on port: 8675') !== -1, 'live reload server should have been started on port 35729.');
|
test.ok(result.indexOf('Live reload server started on localhost:8675') !== -1, 'live reload server should have been started on localhost:8675.');
|
||||||
test.ok(result.indexOf('Live reloading lib/one.js...') !== -1, 'live reload should have triggered on lib/one.js');
|
test.ok(result.indexOf('Live reloading lib/one.js...') !== -1, 'live reload should have triggered on lib/one.js');
|
||||||
resultData = JSON.parse(resultData);
|
resultData = JSON.parse(resultData);
|
||||||
test.equal(resultData.tinylr, 'Welcome', 'tinylr server should have welcomed you.');
|
test.equal(resultData.tinylr, 'Welcome', 'tinylr server should have welcomed you.');
|
||||||
@ -116,7 +116,7 @@ exports.livereload = {
|
|||||||
result = helper.unixify(result);
|
result = helper.unixify(result);
|
||||||
helper.verboseLog(result);
|
helper.verboseLog(result);
|
||||||
test.ok(result.indexOf('I ran before livereload.') !== -1, 'task should have ran before live reload.');
|
test.ok(result.indexOf('I ran before livereload.') !== -1, 'task should have ran before live reload.');
|
||||||
test.ok(result.indexOf('Live reload server started on port: 9876') !== -1, 'live reload server should have been started on port 9876.');
|
test.ok(result.indexOf('Live reload server started on :9876') !== -1, 'live reload server should have been started on port 9876.');
|
||||||
test.ok(/Live reloading (lib\/one\.js, lib\/two.js|lib\/two.js, lib\/one.js)\.\.\./.test(result), 'live reload should have triggered on lib/one.js and lib/two.js');
|
test.ok(/Live reloading (lib\/one\.js, lib\/two.js|lib\/two.js, lib\/one.js)\.\.\./.test(result), 'live reload should have triggered on lib/one.js and lib/two.js');
|
||||||
resultData = JSON.parse(resultData);
|
resultData = JSON.parse(resultData);
|
||||||
test.equal(resultData.tinylr, 'Welcome', 'tinylr server should have welcomed you.');
|
test.equal(resultData.tinylr, 'Welcome', 'tinylr server should have welcomed you.');
|
||||||
@ -137,7 +137,7 @@ exports.livereload = {
|
|||||||
result = helper.unixify(result);
|
result = helper.unixify(result);
|
||||||
helper.verboseLog(result);
|
helper.verboseLog(result);
|
||||||
test.ok(result.indexOf('I ran before livereload.') !== -1, 'task should have ran before live reload.');
|
test.ok(result.indexOf('I ran before livereload.') !== -1, 'task should have ran before live reload.');
|
||||||
test.ok(result.indexOf('Live reload server started on port: 1337') !== -1, 'live reload server should have been started on port 1337.');
|
test.ok(result.indexOf('Live reload server started on :1337') !== -1, 'live reload server should have been started on port 1337.');
|
||||||
test.ok(result.indexOf('Live reloading lib/one.js...') !== -1, 'live reload should have triggered on lib/one.js');
|
test.ok(result.indexOf('Live reloading lib/one.js...') !== -1, 'live reload should have triggered on lib/one.js');
|
||||||
resultData = JSON.parse(resultData);
|
resultData = JSON.parse(resultData);
|
||||||
test.equal(resultData.tinylr, 'Welcome', 'tinylr server should have welcomed you.');
|
test.equal(resultData.tinylr, 'Welcome', 'tinylr server should have welcomed you.');
|
||||||
@ -157,7 +157,7 @@ exports.livereload = {
|
|||||||
}], function(result) {
|
}], function(result) {
|
||||||
result = helper.unixify(result);
|
result = helper.unixify(result);
|
||||||
helper.verboseLog(result);
|
helper.verboseLog(result);
|
||||||
test.ok(result.indexOf('Live reload server started on port: 35729') !== -1, 'live reload server should have been started on port 35729.');
|
test.ok(result.indexOf('Live reload server started on :35729') !== -1, 'live reload server should have been started on port 35729.');
|
||||||
test.ok(result.indexOf('Live reloading lib/one.js...') !== -1, 'live reload should have triggered on lib/one.js');
|
test.ok(result.indexOf('Live reloading lib/one.js...') !== -1, 'live reload should have triggered on lib/one.js');
|
||||||
resultData = JSON.parse(resultData);
|
resultData = JSON.parse(resultData);
|
||||||
test.equal(resultData.tinylr, 'Welcome', 'tinylr server should have welcomed you.');
|
test.equal(resultData.tinylr, 'Welcome', 'tinylr server should have welcomed you.');
|
||||||
|
Loading…
Reference in New Issue
Block a user