diff --git a/lib/c8yRequest.js b/lib/c8yRequest.js index da2878a..5635ba6 100644 --- a/lib/c8yRequest.js +++ b/lib/c8yRequest.js @@ -6,6 +6,16 @@ var Q = require('q'), var credentials; process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; module.exports = function (grunt) { + var LOCAL_PROXY = grunt.config('cumulocity.localproxy'); + + if (LOCAL_PROXY) { + request = request.defaults({ + proxy: LOCAL_PROXY + }); + grunt.log.debug('LOCAL PROXY: ', LOCAL_PROXY); + } + + return { setCredentials: function (_credentials) { credentials = _credentials; @@ -38,6 +48,10 @@ module.exports = function (grunt) { grunt.log.debug('REQUEST: ' + url); grunt.log.debug(' ' + method); grunt.log.debug(' ' + type); + grunt.log.debug('LOCAL PROXY', grunt.config('cumulocity.localproxy')); + + + request({ url : url, method: method, diff --git a/package.json b/package.json index 26cc644..60bec51 100644 --- a/package.json +++ b/package.json @@ -8,15 +8,26 @@ "node": ">=0.10" }, "dependencies": { + "JSONPath": "^0.10.0", "connect-static-transform": "^0.7.0", - "http-proxy": "^1.1.4", + "grunt": "^0.4.5", + "grunt-angular-gettext": "^2.1.0", + "grunt-angular-templates": "^0.5.5", + "grunt-contrib-clean": "^0.5.0", + "grunt-contrib-compress": "^0.12", + "grunt-contrib-connect": "^0.7.1", + "grunt-contrib-copy": "^0.5.0", + "grunt-contrib-cssmin": "^0.9.0", + "grunt-contrib-less": "^0.11.1", + "grunt-contrib-uglify": "^0.4.0", + "grunt-contrib-watch": "^0.6.1", + "http-proxy": "1.13.2", "inquirer": "^0.5.1", "lodash": "^2.4.1", "moment": "^2.10.3", "q": "^1.0.1", "request": "^2.36.0", - "shelljs": "^0.5.0", - "JSONPath": "^0.10.0" + "shelljs": "^0.5.0" }, "peerDependencies": { "grunt-contrib-clean": "^0.5.0", @@ -35,7 +46,6 @@ "grunt-mocha-test": "^0.12.7", "mocha": "^2.2.5", "proxyquire": "^1.5.0", - "sinon": "^1.15.3", - "grunt": "^0.4.5" + "sinon": "^1.15.3" } } diff --git a/tasks/grunt-cumulocity-server.js b/tasks/grunt-cumulocity-server.js index 197eb6d..734f68e 100644 --- a/tasks/grunt-cumulocity-server.js +++ b/tasks/grunt-cumulocity-server.js @@ -3,14 +3,16 @@ var url = require('url'), fs = require('fs'), _ = require('lodash'), st = require('connect-static-transform'), - httpProxy = require('http-proxy'); + httpProxy = require('http-proxy'), + request = require('request'); module.exports = function (grunt) { 'use strict'; var port = grunt.config('cumulocity.port') || grunt.option('port'); grunt.config('cumulocity.port', port); - + var LOCAL_PROXY = grunt.config('cumulocity.localproxy'); + var LOCAL_PROXY_AUTH = LOCAL_PROXY ? url.parse(LOCAL_PROXY).auth : undefined; var TARGET = [ grunt.config('cumulocity.protocol'), '://', @@ -19,9 +21,15 @@ module.exports = function (grunt) { ].join(''), proxy = httpProxy.createServer({ secure: false, - target: TARGET + target: TARGET, }); + if (LOCAL_PROXY) { + request = request.defaults({ + proxy: LOCAL_PROXY + }); + grunt.log.debug('LOCAL PROXY: ', LOCAL_PROXY); + } function isCorePresent() { return !!getApp('core'); @@ -154,6 +162,7 @@ module.exports = function (grunt) { }; } + return req.pipe(request(TARGET + req.url)).pipe(res); return proxy.web(req, res); } else { next();