e509e508b775865b93004c6a71180855cf8a0f7a.svn-base
1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* grunt
* http://gruntjs.com/
*
* Copyright (c) 2012 "Cowboy" Ben Alman
* Licensed under the MIT license.
* https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
*/
module.exports = function(grunt) {
// Nodejs libs.
var path = require('path');
// External libs.
var connect = require('connect');
// ==========================================================================
// TASKS
// ==========================================================================
grunt.registerTask('server', 'Start a static web server.', function() {
// Get values from config, or use defaults.
var port = grunt.config('server.port') || 8000;
var base = path.resolve(grunt.config('server.base') || '.');
var middleware = [
// Serve static files.
connect.static(base),
// Make empty directories browsable. (overkill?)
connect.directory(base)
];
// If --debug was specified, enable logging.
if (grunt.option('debug')) {
connect.logger.format('grunt', ('[D] server :method :url :status ' +
':res[content-length] - :response-time ms').magenta);
middleware.unshift(connect.logger('grunt'));
}
// Start server.
grunt.log.writeln('Starting static web server on port ' + port + '.');
connect.apply(null, middleware).listen(port);
});
};