Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with grunt-contrib-connect 0.8.0 #65

Closed
zenhunt opened this issue Jun 27, 2014 · 8 comments
Closed

Error with grunt-contrib-connect 0.8.0 #65

zenhunt opened this issue Jun 27, 2014 · 8 comments

Comments

@zenhunt
Copy link

zenhunt commented Jun 27, 2014

This plugin is broken in usage with grunt connect 0.8.0, updating to this version will result in the following error:

Running "connect:devproxy" (connect) task
Verifying property connect.devproxy exists in config...OK
File: [no files]
Options: protocol="http", port=9997, hostname="closedhost", base="tmp", directory=null, keepalive=false, debug=false, livereload, open=false, useAvailablePort=false,onCreateServer=null, middleware=undefined
Warning: Arguments to path.resolve must be strings Use --force to continue.

Please fix. :)

Best Regards,

@zenhunt

@kozmic
Copy link

kozmic commented Jul 14, 2014

+1
Downgrading grunt-contrib-connect to 0.7.1 is a workaround.

@dansomething
Copy link
Collaborator

As of v0.1.11 this plugin work with fine with grunt-contrib-connect 0.8.0.

@dansomething
Copy link
Collaborator

Closing since v0.1.11 is released. Please re-open if this is still an issue.

@tony-kerz
Copy link

i just encountered the same issue with grunt-contrib-connect/0.8.0 and grunt-connect-proxy/0.1.11.

downgrading to grunt-contrib-connect/0.7.1 made the issue go away...

let me know if i can provide any more information to assist troubleshooting...

regards,
tony.

@tony-kerz
Copy link

so... the problem didn't actually go away when using grunt-contrib-connect/0.7.1, this warning went away:

Warning: Arguments to path.resolve must be strings Use --force to continue.

but i continued to have other issues at runtime.

it actually turned out to be operator error with this grunt config:

        connect: {
            server: {
                options: {
                    port: 9000,
                    hostname: 'localhost',
                    base: 'build',
                    middleware: function (connect, options) {
                        var proxy = require('grunt-connect-proxy/lib/utils').proxyRequest;
                        console.log("middleware: options=%o", options);
                        return [
                            // Include the proxy first
                            proxy,
                            // Serve static files.
                            connect.static(options.base)
                            // Make empty directories browsable.
                            //connect.directory(options.base)
                        ];
                    },
                    debug: true
                },
                proxies: [
                    {
                        context: '/api',
                        host: 'localhost',
                        port: 3000
                    }
                ]
            }
        },

when i dumped the options arg via console.log it showed that options.base was actually an array by the time it got passed into the function specified as the middleware field.

so something like what the author of this post shown below would be the real solution to the issue:

middleware: function(connect, options) {
    var middlewares = [];
    var directory = options.directory ||
      options.base[options.base.length - 1];
    if (!Array.isArray(options.base)) {
        options.base = [options.base];
    }

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

    // Make directory browse-able.
    middlewares.push(connect.directory(directory));
    return middlewares;
}

regards,
tony.

@char-star
Copy link

Perfect life saver! Thanks Tony.

@zenhunt
Copy link
Author

zenhunt commented Mar 14, 2015

Tony! n1. Thank you.

@merriam
Copy link

merriam commented Apr 27, 2015

Whee! Is still broken btw. Will try the workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants