gruntjs / grunt-contrib-connect

Start a static web server.
http://gruntjs.com
MIT License
714 stars 146 forks source link

the third arguments of option middlewares is undefined #175

Closed aflext closed 9 years ago

aflext commented 9 years ago

I use middleware to mock static json data,but the middleware only have 2 arguments,the third argument which should be an array turn outs to be unddfined. my gruntfile :

   // The actual grunt server settings
        connect: {
            options: {
                port: 9000,
                livereload: 35729,
                // Change this to '0.0.0.0' to access the server from outside
                hostname: '0.0.0.0'
            },
            server: {
                options: {
                    open: 'http://localhost:9000',
                    base: [
                        '<%= yeoman.dist %>',
                        '<%= yeoman.tmp %>',
                        '<%= yeoman.app %>'
                    ],
                    middleware: function(connect, options, middlewares) {
                        var bodyParser = require('body-parser');
                        // the middlewares is undefined,so here i encountered an error.
                         middlewares.unshift(
                            connect().use(bodyParser.urlencoded({
                                extended: false
                            })),
                            function(req, res, next) {
                                if (req.url !== '/hello/world') return next();
                                res.end('Hello, world from port #' + options.port + '!');
                            }
                        );
                        return middlewares;
                    }
                }
            },
            test: {
                options: {
                    port: 9001,
                    base: [
                        '<%= yeoman.tmp %>',
                        'test',
                        '<%= yeoman.app %>'
                    ]
                }
            },
            dist: {
                options: {
                    open: true,
                    base: '<%= yeoman.dist %>',
                    livereload: false
                }
            }
        },

The error is :

Running "connect:server" (connect) task
Warning: Cannot read property 'unshift' of undefined Use --force to continue.

Aborted due to warnings.