Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ grunt.initConfig({
```
#### Adding the middleware

##### With Livereload
##### With Livereload and grunt-contrib-connect <= 0.10

Add the middleware call from the connect option middleware hook
```js
Expand Down Expand Up @@ -82,6 +82,52 @@ Add the middleware call from the connect option middleware hook
}
```

##### With Livereload and grunt-contrib-connect >= 0.11

grunt-contrib-connect 0.11 onwards is using connect 3.x under the hood. This means
that `connect.static` and `connect.index` are no longer available. So, if you run
into an error like `connect.static is not a function`, you might be using connect 3.x.

To fix this problem, load [`serve-static`](https://www.npmjs.com/package/serve-static) and/or
[`serve-index`](https://www.npmjs.com/package/serve-index) and configure the connect task as
follows.

```js

var serveStatic = require('serve-static');
var serveIndex = require('serve-index');

grunt.initConfig({
//...
connect: {
livereload: {
options: {
middleware: function (connect, options) {
if (!Array.isArray(options.base)) {
options.base = [options.base];
}

// Setup the proxy
var middlewares = [require('grunt-connect-proxy/lib/utils').proxyRequest];

// Serve static files.
options.base.forEach(function(base) {
middlewares.push(serveStatic(base));
});

// Make directory browse-able.
var directory = options.directory || options.base[options.base.length - 1];
middlewares.push(serveIndex(directory));

return middlewares;
}
}
}
}
});
```


##### Without Livereload

It is possible to add the proxy middleware without Livereload as follows:
Expand Down