drewzboto / grunt-connect-proxy

Grunt Connect support for proxying API calls during development
MIT License
424 stars 122 forks source link

Adding middleware w/ livereload breaks with grunt-contrib-connect 0.11.0 #112

Open yankee42 opened 9 years ago

yankee42 commented 9 years ago

The example "Adding the middleware - With Livereload" in the README.md breaks when updating grunt-contrib-connect to version 0.11.0 because the connect parameter is missing the methods static and directory. With version 0.10.1 it still works fine. Here is the error:

Running "connect:server" (connect) task
Warning: Object function createServer() {
  function app(req, res, next){ app.handle(req, res, next); }
  merge(app, proto);
  merge(app, EventEmitter.prototype);
  app.route = '/';
  app.stack = [];
  return app;
} has no method 'static' Use --force to continue.

The version history for grunt-contrib-connect says the change in this version was: update to connect 3.. I am not familiar with how connect works internally but I guess that the API has changed and the documentation here (README.md) needs to be changed as well.

Nadrendion commented 8 years ago

+1 I have the very same issue.

whitetrefoil commented 8 years ago

This seems work...

middleware: function(connect, options, middlewares) {
  middlewares.unshift(require('grunt-connect-proxy/lib/utils').proxyRequest);
  return middlewares;
}
zeripath commented 8 years ago

Hi!

So the issue appears to be that grunt-contrib-connect@0.11.0 moved to using connect@3.4.0 which has a different syntax for serving static files. I've just put a bug fix in to grunt-contrib-connect to ask them to make it clearer that the syntax has changed (grunt-contrib-connect#205) however, to be clearer here the fix is to:

  1. At the top of your Gruntfile.js you need to add:

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

  2. Then wherever connect.static is used you simply replace:

    connect.static(...) with: serveStatic(...)

Or at least that appears to be it!