Thursday, March 10, 2016

How to set up grunt live-reload task with nginx and local tomcat

Leave a Comment

I am used to a development environment where I run a little node server locally and make my service calls to a remote REST API. I'm now in a setup where everything is local. There's a local tomcat instance running the REST API and nginx is being used to route calls from my angular app to the tomcat server. The problem I'm having is running my grunt server task - it starts up a connect server that runs on port 9000; Live reload functionality is unavailable because nginx is listening on port 80, so to see changes I have to got to localhost/xyz. Changing the nginx.server.listen port to port 9000 does not work either.

#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/*; 

}

What I'd like to be able to do is pretty standard stuff really - watch my .scss and es6 files and compile on change, then hot reload the browser when changes are made. Here is the connect process in my 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)         ];       }     }   }, 

I'm unfamiliar with nginx and tomcat, but pretty comfortable in node build tools; gulp more than grunt but this is what I have inherited ¯\_(ツ)_/¯

Do I need to change something in my nginx setup to make this happen, or in my grunt setup, or both?

1 Answers

Answers 1

I don't see the 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)         ];       }     }   }, 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment