gruntjs / grunt-contrib-connect

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

connect.static is undefined after update #191

Closed paveleremin closed 9 years ago

paveleremin commented 9 years ago

After update "grunt-contrib-connect" from ^0.7.1 to ^0.11.2, my code is broken:

connect: {
    options: {
        port: 9000,
        // Change this to '0.0.0.0' to access the server from outside.
        hostname: 'localhost',
        livereload: 35729
    },
    livereload: {
        options: {
            open: true,
            middleware: function (connect){
                var modRewrite = require('connect-modrewrite');

                return [
                    modRewrite(['^[^\\.]*$ /index.html [L]']),
                    connect.static('.tmp'),
                    connect().use(
                        '/bower_components',
                        connect.static('./bower_components')
                    ),
                    connect.static(appConfig.app)
                ];
            }
        }
    },

now connect.static is undefined. Is it correct?

vladikoff commented 9 years ago

we updated to connect 3, there is no connect.static anymore, see https://github.com/gruntjs/grunt-contrib-connect#roll-your-own

eddiemonge commented 8 years ago

That really isn't much of a migration path.

Perhaps the docs could say:

Connect 3 no longer uses connect.static. Similar functionality is available using serve-static. To use this:

Before:

            return [
                modRewrite(['^[^\\.]*$ /index.html [L]']),
                connect.static('.tmp'),
                connect().use(
                    '/bower_components',
                    connect.static('./bower_components')
                ),
                connect.static(appConfig.app)
            ];

After:

            return [
                modRewrite(['^[^\\.]*$ /index.html [L]']),
                serveStatic('.tmp'),
                connect().use(
                    '/bower_components',
                    serveStatic('./bower_components')
                ),
                serveStatic(appConfig.app)
            ];
pgrodrigues commented 8 years ago

Thanks @eddiemonge.

spdaly commented 8 years ago

Thanks @eddiemonge

frazras commented 8 years ago

Does anyone get:

TypeError: object is not a function

for

connect().use(
                    '/bower_components',
                    connect.static('./bower_components')
                ),

Im confused how it worked in the first place because in connect.static('.tmp'), was used here as an object then right after connect().use( is used as a function

Chris2011 commented 8 years ago

I use serverStatic too and it works like a charme, what doesn't work is this:

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

connect.directory is not a function, is the error message, the same as for .static. How can I fix that? Couldn't find a solution.

overmedia commented 8 years ago

If is not backwards compatible I think that version number should be changed to 1.[something].[something]. Read this: version [Major].[Minor].[Patch] Major = “breaking changes” – Increment MAJOR version when you have removed or changed a feature, and dependent modules will have to modified to be compatible with the new version.

Minor = “new feature” – Increment MINOR version when you have added a feature, but the module is backwards compatible.

Patch = “bugfix” – Increment PATCH version when you have fixed a problem, but not broken or changed anything else.

source: http://developer.telerik.com/featured/mystical-magical-semver-ranges-used-npm-bower/

sterichards commented 6 years ago

return [ modRewrite(['^[^\.]*$ /index.html [L]']), connect.static('.tmp'), connect().use( '/bower_components', connect.static('./bower_components') ), connect.static(appConfig.app) ];

sterichards commented 6 years ago

I've found the best solution to be roll-back

Spent 2 hours trying various suggested changes and nothing works.

Rolled back and it works like a charm