如何使用nginx和本地tomcat设置grunt live-reload任务

时间:2016-02-01 15:42:15

标签: angularjs tomcat nginx gruntjs livereload

我习惯于在本地运行一个小节点服务器的开发环境,并对远程REST API进行服务调用。我现在正处于一切都是本地的设置中。有一个运行REST API的本地tomcat实例,nginx用于将来自我的角度应用程序的调用路由到 tomcat服务器。我遇到的问题是运行我的grunt服务器任务 - 它启动一个在端口9000上运行的连接服务器;实时重新加载功能不可用,因为nginx正在侦听端口80,因此要查看我必须访问localhost / xyz的更改。将nginx.server.listen端口更改为端口9000也不起作用。

#user  nobody;
worker_processes  1;

error_log  logs/error.log;

events {
    worker_connections  1024;
}

http {
  include       mime.types;
  default_type  application/octet-stream;
  sendfile        on;
  keepalive_timeout  65;

  server {
        listen 80;
        root /Users/me/dev/angular-project/app;  //this looks at my angular app

        index index.html index.htm;
        server_name localhost;
        location / {
           try_files $uri /index.html?v=100515130;

        }
        location /services1 {
                proxy_pass      http://localhost:8080/services1; //this is one of my services call addresses
                proxy_set_header Host localhost;
        }

        location /services2 {
                proxy_pass      http://localhost:8080/services2;  //this is another service call address
                proxy_set_header Host localhost;
        }

}

include servers/*;

}

我希望能够做的是非常标准的东西 - 观看我的.scss和es6文件并在更改时进行编译,然后在进行更改时热重新加载浏览器。这是我的gruntfile中的连接过程:

connect: {
  options: {
    port: 9001,
    // Change this to '0.0.0.0' to access the server from outside.
    //hostname: 'localhost'
      hostname: '0.0.0.0'
  },
  livereload: {
    options: {
      middleware: function (connect) {
        return [
         modRewrite([
                    '^[^\\.]*$ /index.html [L]'
                  ]),                
          lrSnippet,
          mountFolder(connect, '.tmp'),
          mountFolder(connect, yeomanConfig.app)
        ];
      }
    }
  },

我不熟悉nginx和tomcat,但在节点构建工具方面相当不错;吞咽不止咕噜声,但这是我继承的¯\ _(ツ)_ /¯

我是否需要在我的nginx设置中更改某些内容以实现此目的,或者在我的grunt设置中,或两者都改变​​?

1 个答案:

答案 0 :(得分:0)

我没有看到options.livereload

connect: {
  options: {
    port: 9001,
    // Change this to '0.0.0.0' to access the server from outside.
    //hostname: 'localhost'
      hostname: '0.0.0.0'
      livereload: 35729
  },
  livereload: {
    options: {
      livereload: true 
      middleware: function (connect) {
        return [
          modRewrite([
            '^[^\\.]*$ /index.html [L]'
          ]),                
          lrSnippet,
          mountFolder(connect, '.tmp'),
          mountFolder(connect, yeomanConfig.app)
        ];
      }
    }
  },