javascript - creating dynamic servers in Gulp using connect -
is possible check if server port taken before creating in gulp?
i'm doing right now:
/** * start livereload server */ gulp.task('connect', function() { var connect = require('connect'), app = connect() .use(require('connect-livereload')({ port: livereloadport })) .use(connect.static('app')) .use(connect.static('.tmp')) .use(connect.directory('app')); require('http').createserver(app) .listen(serverport) .on('listening', function () { console.log('started connect web server on http://localhost:' + serverport); }); }); gulp.task('serve', ['connect', 'styles'], function() { require('opn')('http://localhost:' + serverport); });
i'd able have server port dynamic , check if port in use. possible?
thanks @ilanfrumer found solution using this.
implemented this:
var serverport; /** * start livereload server */ gulp.task('connect', function () { var portfinder = require('portfinder'), connect = require('connect'), app = connect() .use(require('connect-livereload')({ port: 35729 })) .use(connect.static('app')) .use(connect.static('.tmp')) .use(connect.directory('app')); portfinder.getport(function (err, port) { serverport = port; require('http').createserver(app) .listen(port) .on('listening', function () { console.log('started connect web server on http://localhost:' + port); }); }); }); gulp.task('serve', ['connect', 'styles'], function () { require('opn')('http://localhost:' + serverport); });
there other factors taking place in functions above, meat of there. again @ilanfrumer!
Comments
Post a Comment