From ed66aef4a1471b34ed0d67ab6520019a75c6059d Mon Sep 17 00:00:00 2001 From: Luis Confraria Date: Wed, 20 Apr 2016 14:27:52 +0200 Subject: [PATCH 1/5] hg flow, add branch `feature/fix_corporate_proxy`. From 69925949b78d4a3d0e2ab78a5f734ba44aba987e Mon Sep 17 00:00:00 2001 From: Luis Confraria Date: Wed, 20 Apr 2016 14:28:10 +0200 Subject: [PATCH 2/5] add an option for local proxy --- lib/c8yRequest.js | 14 ++++++++++++++ package.json | 20 +++++++++++++++----- tasks/grunt-cumulocity-server.js | 15 ++++++++++++--- 3 files changed, 41 insertions(+), 8 deletions(-) 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(); From 049b448fadd79b478acad4c137d9b231dec21bd0 Mon Sep 17 00:00:00 2001 From: Luis Confraria Date: Fri, 29 Apr 2016 12:08:35 +0100 Subject: [PATCH 3/5] update requests. remove comma --- package.json | 2 +- tasks/grunt-cumulocity-server.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 60bec51..c1a310f 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "lodash": "^2.4.1", "moment": "^2.10.3", "q": "^1.0.1", - "request": "^2.36.0", + "request": "2.72.0", "shelljs": "^0.5.0" }, "peerDependencies": { diff --git a/tasks/grunt-cumulocity-server.js b/tasks/grunt-cumulocity-server.js index 734f68e..16b8141 100644 --- a/tasks/grunt-cumulocity-server.js +++ b/tasks/grunt-cumulocity-server.js @@ -21,7 +21,7 @@ module.exports = function (grunt) { ].join(''), proxy = httpProxy.createServer({ secure: false, - target: TARGET, + target: TARGET }); if (LOCAL_PROXY) { From a68b3c5b3464e5527c636bf943b1be61600b5760 Mon Sep 17 00:00:00 2001 From: Luis Confraria Date: Fri, 29 Apr 2016 13:05:56 +0100 Subject: [PATCH 4/5] remove unused variable --- tasks/grunt-cumulocity-server.js | 1 - 1 file changed, 1 deletion(-) diff --git a/tasks/grunt-cumulocity-server.js b/tasks/grunt-cumulocity-server.js index 16b8141..2a62471 100644 --- a/tasks/grunt-cumulocity-server.js +++ b/tasks/grunt-cumulocity-server.js @@ -12,7 +12,6 @@ module.exports = function (grunt) { 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'), '://', From 416b38b574922dcaf582769b7c9a4149d47b46d1 Mon Sep 17 00:00:00 2001 From: Luis Confraria Date: Fri, 29 Apr 2016 15:50:03 +0100 Subject: [PATCH 5/5] Close branch feature/fix_corporate_proxy