Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 840f96b

Browse files
Enable proxy using for http requests
Rename the following config options: - FIDDLER_HOSTNAME to PROXY_HOSTNAME - PROXY_TO_FIDDLER to USE_PROXY Add PROXY_PORT option to config with default value 8888. Add ConfigBase class which should be used as a base for CLI specific configs. Required for NativeScript/nativescript-cli#297 and NativeScript/nativescript-cli#302
1 parent f2bc130 commit 840f96b

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

config-base.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
///<reference path="../.d.ts"/>
2+
"use strict";
3+
4+
import path = require("path");
5+
import util = require("util");
6+
7+
export class ConfigBase implements IConfiguration {
8+
constructor(protected $fs: IFileSystem) { }
9+
10+
protected loadConfig(name: string): IFuture<any> {
11+
var configFileName = this.getConfigPath(name);
12+
return this.$fs.readJson(configFileName);
13+
}
14+
15+
protected getConfigPath(filename: string): string {
16+
return path.join(__dirname, "../../config/", filename + ".json");
17+
}
18+
}

definitions/config.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ declare module Config {
1313
sevenZipFilePath: string;
1414
}
1515

16-
1716
interface IConfig {
1817
AB_SERVER?: string;
1918
AB_SERVER_PROTO?: string;
2019
DEBUG?: boolean;
21-
FIDDLER_HOSTNAME?: string;
20+
PROXY_HOSTNAME?: string;
21+
USE_PROXY?: boolean;
22+
PROXY_PORT?: number;
2223
CI_LOGGER?: boolean;
23-
PROXY_TO_FIDDLER?: boolean;
2424
TYPESCRIPT_COMPILER_OPTIONS?: any;
2525
}
2626
}

http-client.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,18 @@ export class HttpClient implements Server.IHttpClient {
4444
var pipeTo = options.pipeTo;
4545
delete options.pipeTo;
4646

47-
var proto = this.$config.PROXY_TO_FIDDLER ? "http" : requestProto;
47+
var proto = this.$config.USE_PROXY ? "http" : requestProto;
4848
var http = require(proto);
4949

5050
options.headers = options.headers || {};
5151
var headers = options.headers;
5252

53-
if (this.$config.PROXY_TO_FIDDLER) {
53+
if(this.$config.USE_PROXY) {
5454
options.path = requestProto + "://" + options.host + options.path;
5555
headers.Host = options.host;
56-
options.host = this.$config.FIDDLER_HOSTNAME;
57-
options.port = 8888;
56+
options.host = this.$config.PROXY_HOSTNAME;
57+
options.port = this.$config.PROXY_PORT;
58+
this.$logger.trace("Using proxy with host: %s, port: %d, path is: %s", options.host, options.port, options.path);
5859
}
5960

6061
if (!headers.Accept || headers.Accept.indexOf("application/json") < 0) {

0 commit comments

Comments
 (0)