grunt-contrib-connect
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -5,3 +5,3 @@ /* | ||
* | ||
* Copyright (c) 2012 "Cowboy" Ben Alman, contributors | ||
* Copyright (c) 2013 "Cowboy" Ben Alman, contributors | ||
* Licensed under the MIT license. | ||
@@ -11,2 +11,4 @@ */ | ||
'use strict'; | ||
var path = require('path'); | ||
var certs = path.join(__dirname, 'tasks', 'certs'); | ||
@@ -41,2 +43,18 @@ module.exports = function(grunt) { | ||
}, | ||
custom_https: { | ||
options: { | ||
port: 8001, | ||
protocol: 'https', | ||
} | ||
}, | ||
custom_https_certs: { | ||
options: { | ||
port: 8002, | ||
protocol: 'https', | ||
key: grunt.file.read(path.join(certs, 'server.key')).toString(), | ||
cert: grunt.file.read(path.join(certs, 'server.crt')).toString(), | ||
ca: grunt.file.read(path.join(certs, 'ca.crt')).toString(), | ||
passphrase: 'grunt', | ||
} | ||
}, | ||
custom_middleware: { | ||
@@ -55,2 +73,8 @@ options: { | ||
}, | ||
multiple_base: { | ||
options: { | ||
base: ['test', 'docs'], | ||
port: 9002 | ||
} | ||
} | ||
} | ||
@@ -57,0 +81,0 @@ }); |
{ | ||
"name": "grunt-contrib-connect", | ||
"description": "Start a connect web server.", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"homepage": "https://github.com/gruntjs/grunt-contrib-connect", | ||
@@ -31,8 +31,9 @@ "author": { | ||
"dependencies": { | ||
"connect": "~2.7.3" | ||
"connect": "~2.7.11", | ||
"connect-livereload": "~0.2.0" | ||
}, | ||
"devDependencies": { | ||
"grunt-contrib-jshint": "~0.2.0", | ||
"grunt-contrib-nodeunit": "~0.1.2", | ||
"grunt-contrib-internal": "~0.4.2", | ||
"grunt-contrib-jshint": "~0.6.4", | ||
"grunt-contrib-nodeunit": "~0.2.0", | ||
"grunt-contrib-internal": "~0.4.6", | ||
"grunt": "~0.4.0" | ||
@@ -39,0 +40,0 @@ }, |
@@ -5,3 +5,3 @@ /* | ||
* | ||
* Copyright (c) 2012 "Cowboy" Ben Alman, contributors | ||
* Copyright (c) 2013 "Cowboy" Ben Alman, contributors | ||
* Licensed under the MIT license. | ||
@@ -15,2 +15,5 @@ */ | ||
var connect = require('connect'); | ||
var http = require('http'); | ||
var https = require('https'); | ||
var injectLiveReload = require('connect-livereload'); | ||
@@ -20,2 +23,3 @@ grunt.registerMultiTask('connect', 'Start a connect web server.', function() { | ||
var options = this.options({ | ||
protocol: 'http', | ||
port: 8000, | ||
@@ -25,14 +29,27 @@ hostname: 'localhost', | ||
keepalive: false, | ||
debug: false, | ||
livereload: false, | ||
middleware: function(connect, options) { | ||
return [ | ||
var middlewares = []; | ||
options.base.forEach(function(base) { | ||
// Serve static files. | ||
connect.static(options.base), | ||
middlewares.push(connect.static(base)); | ||
// Make empty directories browsable. | ||
connect.directory(options.base), | ||
]; | ||
middlewares.push(connect.directory(base)); | ||
}); | ||
return middlewares; | ||
} | ||
}); | ||
if (options.protocol !== 'http' && options.protocol !== 'https') { | ||
grunt.fatal('protocol option must be \'http\' or \'https\''); | ||
} | ||
// Normalize whether base is an array | ||
options.base = Array.isArray(options.base) ? options.base : [options.base]; | ||
// Connect requires the base path to be absolute. | ||
options.base = path.resolve(options.base); | ||
options.base = options.base.map(function(base) { | ||
return path.resolve(base); | ||
}); | ||
@@ -52,3 +69,3 @@ // Connect will listen to all interfaces if hostname is null. | ||
// If --debug was specified, enable logging. | ||
if (grunt.option('debug')) { | ||
if (grunt.option('debug') || options.debug === true) { | ||
connect.logger.format('grunt', ('[D] server :method :url :status ' + | ||
@@ -59,2 +76,10 @@ ':res[content-length] - :response-time ms').magenta); | ||
// Inject live reload snippet | ||
if (options.livereload !== false) { | ||
if (options.livereload === true) { | ||
options.livereload = 35729; | ||
} | ||
middleware.unshift(injectLiveReload({port: options.livereload})); | ||
} | ||
// Start server. | ||
@@ -65,11 +90,26 @@ var done = this.async(); | ||
var server = connect | ||
.apply(null, middleware) | ||
var app = connect.apply(null, middleware); | ||
var server = null; | ||
if (options.protocol === 'https') { | ||
server = https.createServer({ | ||
key: options.key || grunt.file.read(path.join(__dirname, 'certs', 'server.key')).toString(), | ||
cert: options.cert || grunt.file.read(path.join(__dirname, 'certs', 'server.crt')).toString(), | ||
ca: options.ca || grunt.file.read(path.join(__dirname, 'certs', 'ca.crt')).toString(), | ||
passphrase: options.passphrase || 'grunt', | ||
}, app); | ||
} else { | ||
server = http.createServer(app); | ||
} | ||
server | ||
.listen(options.port, options.hostname) | ||
.on('listening', function() { | ||
var address = server.address(); | ||
grunt.log.writeln('Started connect web server on ' + (address.host || 'localhost') + ':' + address.port + '.'); | ||
grunt.config.set('connect.' + taskTarget + '.options.host', address.host || 'localhost'); | ||
grunt.log.writeln('Started connect web server on ' + (address.address || 'localhost') + ':' + address.port + '.'); | ||
grunt.config.set('connect.' + taskTarget + '.options.host', address.address || 'localhost'); | ||
grunt.config.set('connect.' + taskTarget + '.options.port', address.port); | ||
grunt.event.emit('connect.' + taskTarget + '.listening', (address.address || 'localhost'), address.port); | ||
if (!keepAlive) { | ||
@@ -76,0 +116,0 @@ done(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
24888
15
191
0
261
3
3
+ Addedconnect-livereload@~0.2.0
+ Addedconnect-livereload@0.2.0(transitive)
Updatedconnect@~2.7.11