drewzboto / grunt-connect-proxy

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

Gruntfile.js middleware setup not working with AngularJs and Rails 4 API #94

Open telagraphic opened 9 years ago

telagraphic commented 9 years ago

I've read a couple of SOF posts and tried the code provided in the GCP Github Page, but they do not proxy any client-side requests to my server. The task is being loaded, but chrome network shows the request does not proxy. I had this working a month ago but deleted the project and could not recover it(Hating myself for that one). Any advice on how to set up the GCP middleware for a Rails4 and AngularJS project?

Here is my Gruntfile.js and necessary project code to review: https://gist.github.com/anonymous/3894d93d83a5a0b61fd0

ghost commented 9 years ago

Where is [require('grunt-connect-proxy/lib/utils').proxyRequest]; and 'configureProxies:server',? According to the docs, you need that:

connect: {
            livereload: {
                options: {
                    middleware: function (connect, options) {
                        if (!Array.isArray(options.base)) {
                            options.base = [options.base];
                        }

                        // Setup the proxy
                        var middlewares = [require('grunt-connect-proxy/lib/utils').proxyRequest];

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

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

                        return middlewares;
                    }
                }
            }
        }
    grunt.registerTask('server', function (target) {
        grunt.task.run([
            'clean:server',
            'compass:server',
            'configureProxies:server',
            'livereload-start',
            'connect:livereload',
            'open',
            'watch'
        ]);
    });