drewzboto / grunt-connect-proxy

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

Error with grunt-contrib-connect 0.8.0 #65

Closed zenhunt closed 10 years ago

zenhunt commented 10 years ago

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 commented 10 years ago

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

dansomething commented 10 years ago

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

dansomething commented 10 years ago

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

tony-kerz commented 10 years ago

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 commented 10 years ago

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 commented 9 years ago

Perfect life saver! Thanks Tony.

zenhunt commented 9 years ago

Tony! n1. Thank you.

merriam commented 9 years ago

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