Monday, November 24, 2014

Running Grunt JS managed application behind a proxy

Unfortunately working in a corporate environment imposes certain constraints, mainly for security reasons, at least when it comes to internet access which is usually accomplished via a http(s) proxy server.
It is not unusual Grunt JS and Bower to be used in modern applications. Grunt JS uses npm to download any plugins, Bower on the other has its own mechanism to resolve and download dependencies.
It is also unfortunate, that none of them utilizes environment variables for proxy configuration; like http_proxy and https_proxy in a Linux environment. For Grunt JS you need to execute

npm config set proxy http://<proxy_host>:<proxy_port>
npm config set https-proxy http://<proxy_host>:<proxy_port>

for http and https proxy settings respectively. Note that no-prefix used the http type of proxy. These commands modify the npm config file; you should be able to verify the effect of the above using: 

npm config list

While Grunt JS settings are stored globally, for Bower, proxy settings are locally stored in the scope of the project. Typically in the root directory of a project there should be a .bowerrc file, you can modify the contents of this file to match the following:

{
    "directory": "app/bower_components",
    "proxy": "http://<proxy_host>:<proxy_port>",
    "https_proxy": "<proxy_host>:<proxy_port>"

}

You may now execute npm install and have all dependencies downloaded in your project.