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

Snapshots not working behind corporate proxy #389

Closed
ticklemepierce opened this issue Jan 3, 2018 · 3 comments · Fixed by #428
Closed

Snapshots not working behind corporate proxy #389

ticklemepierce opened this issue Jan 3, 2018 · 3 comments · Fixed by #428
Assignees
Labels

Comments

@ticklemepierce
Copy link

It seems that node's https module does not honor environment proxy variables (i.e. HTTPS_PROXY) so the snapshots time out with the requests in utils (getJsonFile and downloadFile).

I'm on node 8.7.0 and nativescript 3.4.0. I'm also using 0.9.0 for this package.

@mxth
Copy link

mxth commented Jan 17, 2018

Our CI build breaks because of this. Any workaround?

ERROR in NativeScriptSnapshot. Snapshot generation failed!
Cannot find suitable v8 version! Original error: connect ETIMEDOUT 151.101.64.133:443

@NickIliev
Copy link
Contributor

NickIliev commented Jan 19, 2018

Confirming this one as not implemented feature.

Ping @Pip3r4o @rosen-vladimirov

@rosen-vladimirov suggested implementing the usage of request instead of https.get

@petekanev
Copy link

@ticklemepierce @mxth @ajswago

I can confirm that the snapshot generation does not work while behind a proxy. The problem stems from the fact that node.js does not respect env variables and system proxies by default. The requests made at

and
const request = httpsGet(url, response => {

will not be influenced by HTTPS_PROXY set from the NativeScript CLI, or as a node environment variable.

We are currently reviewing the best way to enable http requests behind a proxy in the snapshot scripts, and will let you know when an update with a fix is released.

As an immediate work-around the https requests can be replaced by those of the request npm package.

const request = require("request");

const downloadFile = (url, destinationFilePath) =>
	new Promise((resolve, reject) => {
		request
			.get(url)
			.on('response', response => 
            switch (response.statusCode) {
				case 200:
					const file = createWriteStream(destinationFilePath, { autoClose: true });
					file.on('error', function (error) {
						return reject(error);
					});
					file.on("finish", function () {
						chmodSync(destinationFilePath, 0755);
						return resolve(destinationFilePath);
					});
					response.pipe(file);
					break;
				case 301:
				case 302:
				case 303:
					const redirectUrl = response.headers.location;
					return this.downloadFile(redirectUrl, destinationFilePath);
				default:
					return reject(new Error("Unable to download file at " + url + ". Status code: " + response.statusCode));
			}
		)
			.on('error', err => {
				return reject(err);
			});
	});

const getJsonFile = url =>
	new Promise((resolve, reject) => {
		request
			.get(url)
			.on('response', res => {
				let body = "";
				res.on("data", chunk => {
					body += chunk;
				})

				res.on("end", () => {
					const data = JSON.parse(body);
					return resolve(data);
				});
			})
			.on("error", err => {
				return reject(err);
			});
	});

sis0k0 added a commit that referenced this issue Jan 29, 2018
Use 'request' node package, which respects environment proxy variables
(i.e. HTTPS_PROXY).

fixes #389
@sis0k0 sis0k0 self-assigned this Jan 29, 2018
@sis0k0 sis0k0 added bug and removed feature labels Jan 29, 2018
sis0k0 added a commit that referenced this issue Feb 15, 2018
Use 'request' node package for https requests and 'proxy-lib' for getting configured proxy settings (see: NativeScript/nativescript-cli:docs/man_pages/general/proxy-set.md@master).

fixes #389
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants