Skip to content

Instantly share code, notes, and snippets.

@ataube
Forked from anonymous/grunt_connect.js
Created December 27, 2012 21:31
Show Gist options
  • Save ataube/4392181 to your computer and use it in GitHub Desktop.
Save ataube/4392181 to your computer and use it in GitHub Desktop.
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
connect: {
server: {
options: {
port: 9001,
base: 'target/build/debug/app',
middleware: function(connect, options) {
var fs = require('fs');
var util = require('util');
var path = require('path');
return [
// Serve static files.
connect.static(options.base),
// Make empty directories browsable.
connect.directory(options.base),
//rewrite all non static/directories resources to index.html, no redirect!
function(req, res, next) {
res.writeHead(200, {
'Content-Type': 'text/html'
});
var stream = fs.createReadStream(path.join(options.base, 'index.html'));
util.pump(stream, res);
}
];
}
}
}
}
});
//##############################################################
//# Dependencies
//###############################################################
grunt.loadNpmTasks('grunt-contrib-connect');
//###############################################################
// # Alias tasks
//###############################################################
grunt.registerTask('default', ['connect']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment