Grunt Livereload + Grunt Connect Proxy

I use Rails for my API, AngularJS on the front panel, and I'm having some problems with working with a proxy server to work with the / grunt file system.

Here is a snippet from my grunt file:

connect: {
      options: {
        port: 9000,
        // Change this to '0.0.0.0' to access the server from outside.
        hostname: 'localhost',
        livereload: 35729
      },
      proxies: [
        {
          context: '/api',
          host: 'localhost',
          port: 3000
        }
      ],
      livereload: {
        options: {
          open: true,
          base: [
            '.tmp',
            '<%= yeoman.app %>'
          ],
          middleware: function (connect, options) {
            var middlewares = [];
            var directory = options.directory || options.base[options.base.length - 1];

            // enable Angular HTML5 mode
            middlewares.push(modRewrite(['!\\.html|\\.js|\\.svg|\\.css|\\.png$ /index.html [L]']));

            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;
          }
        }
      },
      test: {
        options: {
          port: 9001,
          base: [
            '.tmp',
            'test',
            '<%= yeoman.app %>'
          ]
        }
      },
      dist: {
        options: {
          base: '<%= yeoman.dist %>'
        }
      }
    }

If I am 'grunt build' everything works fine - off localhost:3000

However, if I 'grunt serve', it opens a window through 127.0.0.1:9000, and I get 404 to all API calls.

Also under the service, it distorts my background images from the CSS file, I get this warning:

Resource interpreted as Image but transferred with MIME type text/html: "http://127.0.0.1:9000/images/RBP_BG.jpg"

I have not done this before - so I'm doing it all wrong.

+3
source share
3 answers

connect.livereload.middleware.
?

this commit - chore(yeoman-gruntfile-update): configured grunt-connect-proxy .

+5

, , - grunt, configureProxies .

grunt.task.run([
  'clean:server',
  'bower-install',
  'concurrent:server',
  'autoprefixer',
  'configureProxies',
  'connect:livereload',
  'watch'
]);

.

+3

, .

- configureProxies.

:

grunt.registerTask ('serve', ['connect: livereload', 'configureProxies', 'open: server', 'watch']);

and "connect: livereload", "configureProxies". After my test, the order of these two tasks will not affect the results.

github grunt-connect-proxy

0
source

All Articles