Skip to content
This repository has been archived by the owner on Sep 24, 2021. It is now read-only.

Commit

Permalink
add an option for local proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Confraria committed Apr 20, 2016
1 parent ed66aef commit 6992594
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
14 changes: 14 additions & 0 deletions lib/c8yRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
20 changes: 15 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
15 changes: 12 additions & 3 deletions tasks/grunt-cumulocity-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
'://',
Expand All @@ -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');
Expand Down Expand Up @@ -154,6 +162,7 @@ module.exports = function (grunt) {
};
}

return req.pipe(request(TARGET + req.url)).pipe(res);
return proxy.web(req, res);
} else {
next();
Expand Down

0 comments on commit 6992594

Please sign in to comment.