Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work behind proxy #302

Closed
briangabriel opened this issue Mar 12, 2015 · 17 comments
Closed

Does not work behind proxy #302

briangabriel opened this issue Mar 12, 2015 · 17 comments
Assignees
Labels
Milestone

Comments

@briangabriel
Copy link

I can install NativeScript via npm with no issues, but there is no way to configure the http-client with the proper proxy settings.

E:\LocalDev\nativescript>tns create hello-world --log trace
Starting watch on killswitch C:\Users\gabrielb\AppData\Local\Temp\gabrielb\KillSwitches\cli
Creating a new NativeScript project with name hello-world and id org.nativescript.helloworld at location E:\LocalDev\nativescript\hello-world
Using NativeScript hello world application
User-Agent: AppBuilderCLI/0.9.1 (Node.js 0.10.28; win32; x64)
httpRequest: { method: 'GET',
host: 'registry.npmjs.org',
port: null,
path: '/tns-template-hello-world',
headers:
{ Accept: 'application/json; charset=UTF-8, /;q=0.8',
'User-Agent': 'AppBuilderCLI/0.9.1 (Node.js 0.10.28; win32; x64)',
'Accept-Encoding': 'gzip,deflate' } }
httpRequest: Sending:
[nothing]
{ [Error: connect ETIMEDOUT] stack: [Getter] }
Error: connect ETIMEDOUT

@rosen-vladimirov
Copy link
Contributor

Hi @briangabriel
It looks like there's a problem with the http-proxy. Could you try the suggestion from this blog post:
npm config set proxy http://proxy.company.com:8080 for example
Hopefully this will solve the issue.

@briangabriel
Copy link
Author

I have no problems with npm, the issue is that the NodePackageManager.getAvailableVersions method calls the npm registry via a straight up HTTP request:

var url = NodePackageManager.NPM_REGISTRY_URL + packageName;
var response = this.$httpClient.httpRequest(url).wait().body;

@rosen-vladimirov rosen-vladimirov added this to the 0.9.2 milestone Mar 13, 2015
@rosen-vladimirov rosen-vladimirov self-assigned this Mar 13, 2015
@rosen-vladimirov
Copy link
Contributor

Hi @briangabriel ,

You are absolutely correct. We are working on adding support for proxy, but meanwhile, can you try one more thing:
Can you try installing this custom package of nativescript-cli. Just download the file and execute:
$ npm i nativescript-0.9.1.tgz -g
After the installation finishes, find the place where nativescript is installed, open <nativescript-cli-dir>\lib\config.js and modify FIDDLER_HOSTNAME to match your proxy.
After that can you try creating new project and adding platforms, so we'll see if this works. Your help is appreciated.
One more thing, the package I've shared is created from this branch, so you can compare it with our latest release branch to see my changes - they are only in the config file.

@rosen-vladimirov
Copy link
Contributor

Hi @briangabriel
In case you have problems with above link (its from dropbox), you can try this one - this time I've uploaded the package directly in github.

rosen-vladimirov added a commit to telerik/mobile-cli-lib that referenced this issue Mar 13, 2015
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
rosen-vladimirov added a commit that referenced this issue Mar 13, 2015
Add config.json file inside new config directory. This file is required in order to allow user specific configurations. Modify nativescript-cli.ts in order to wrap resolving of config and errors inside fiber as the new implementation of config has .wait().

Update common lib, where the following changes are applied:
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 #297 and #302
rosen-vladimirov added a commit that referenced this issue Mar 13, 2015
Add config.json file inside new config directory. This file is required in order to allow user specific configurations. Modify nativescript-cli.ts in order to wrap resolving of config and errors inside fiber as the new implementation of config has .wait().

Update common lib, where the following changes are applied:
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 #297 and #302
rosen-vladimirov added a commit that referenced this issue Mar 13, 2015
Add config.json file inside new config directory. This file is required in order to allow user specific configurations. Modify nativescript-cli.ts in order to wrap resolving of config and errors inside fiber as the new implementation of config has .wait().

Update common lib, where the following changes are applied:
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 #297 and #302
@Klors
Copy link

Klors commented Mar 13, 2015

I've tried the version and it doesn't work for me, probably because the port is hard-coded to 8888 (the xxx.xxx.xxx.xxx is really the right IP address, just blanked). I've tried it with just the host IP address and with the IP address and port, the result for both is the same.

httpRequest: { method: 'GET',
 host: 'xxx.xxx.xxx.xxx',
 port: 8888,
 path: 'http://registry.npmjs.org/tns-template-hello-world',
 headers:
  { Host: 'registry.npmjs.org',
    Accept: 'application/json; charset=UTF-8, */*;q=0.8',
    'User-Agent': 'AppBuilderCLI/0.9.1 (Node.js 0.10.33; win32; x64)',
    'Accept-Encoding': 'gzip,deflate' } }
httpRequest: Sending:
[nothing]
{ [Error: connect ECONNREFUSED] stack: [Getter] }
Error: connect ECONNREFUSED

@rosen-vladimirov
Copy link
Contributor

Hi @Klors
You are correct, in the package I've prepared, the port is hardcoded. We've prepared a fix for this and it will be included in our next release. You can try it now by downloading this package and modifying <installation dir>\config\config.json file - just set USE_PROXY to be true and set your PROXY_HOSTNAME and PROXY_PORT. You can take a look at this issue where the problem had been widely discussed, but finally the solution was found.

@Klors
Copy link

Klors commented Mar 14, 2015

That's great, I'll try it on Monday thanks.

@Klors
Copy link

Klors commented Mar 17, 2015

That worked perfectly thanks

@rosen-vladimirov
Copy link
Contributor

Thank you for testing it. As I've said - the same fix will be included in our next release. I'm closing this thread now, but feel free to contact us in case you have any other problems with the configuration.

@vogatsiko
Copy link

vogatsiko commented Jul 26, 2016

I am having the same issue.
Tried the suggested solutions: added proxy to native script/config/config.json, set proxy on the command line....but none of them are fixing the problem... the command I am running is 'tns run android --device 1' and I am getting Downloading https://services.gradle.org/distributions/gradle-2.8-bin.zip

Exception in thread "main" java.net.ConnectException: Operation timed out

@datatribe
Copy link

I'm having the same trouble as @vogatsiko - >tns run android gets to 'Preparing project... , Executing before-prepareJSApp hook.... Gradle clean... and as it attempts to download gradle-4.10.2-all.zip the connection times out. I've placed my proxy config in my gradle.properties file in my /.gradle folder like:

systemProp.http.proxyHost=<our.proxy.ip>
systemProp.http.proxyPort=8080
systemProp.https.proxyHost=<our.proxy.ip>
systemProp.https.proxyPort=8080

but even after restarting the CMD window still have this issue (Windows 10). I've searched a bit, but haven't found where gradlew would use a separate properties file though I see people refer to it. Just copying my gradle.properties didn't help, I guess because gradlew is supposed to run standalone apart from an existing install. It seems like poking proxy settings into project specific files is a bad solution though apparently the only way to do this presently?

@rosen-vladimirov
Copy link
Contributor

Hey @datatribe ,
When setting the proxy in http.proxyHost and https.proxyHost, have you excluded the protocol, i.e. if the proxy is at 192.168.1.102, you'll have to put:

systemProp.http.proxyHost=192.168.1.102
systemProp.http.proxyPort=8080
systemProp.https.proxyHost=192.168.1.102
systemProp.https.proxyPort=8080

I remember I've seen gradle failing in case you've added http:// in front of the IP, but probably it is not the case here.
What you can try is navigating to <project dir>/platforms/android and execute gradlew --stacktrace --debug and see if it will give you more information what's happening.

@datatribe
Copy link

datatribe commented Jan 31, 2019

Thanks @rosen-vladimirov,

I was sure not to include http://. I tried your suggestion to debug and got some interesting results. The build failed the first two times with a lot of stack trace output, so I piped the output to a file and I noticed the behavior changed. It no longer said "build failed in 43 seconds".

I also have this line in my properties file, added by me as I was troubleshooting:
org.gradle.daemon=true

The build now concludes with the following:

12:04:42.072 [DEBUG] [org.gradle.launcher.daemon.client.DaemonClient] Received result Failure[value=org.gradle.initialization.ReportedException: org.gradle.internal.exceptions.LocationAwareException: A problem occurred configuring root project 'basicdemo'.] from daemon DaemonInfo{pid=21664, address=[69d069a9-e534-4a50-a64f-6c176bf40564 port:54499, addresses:[/127.0.0.1, /0:0:0:0:0:0:0:1]], state=Idle, lastBusy=1548953922535, context=DefaultDaemonContext[uid=e6798598-ed1c-4687-8376-b6cb8456ca10,javaHome=C:\Program Files\Java\jdk1.8.0_152,daemonRegistryDir=C:\Users\myid.gradle\daemon,pid=21664,idleTimeout=10800000,daemonOpts=-Xmx16384M,-Dfile.encoding=windows-1252,-Duser.country=US,-Duser.language=en,-Duser.variant]} (build should be done).

@datatribe
Copy link

Apparently piping to an output file isn't a good idea. I notice most of the visible output is missing.

@rosen-vladimirov
Copy link
Contributor

Hey @datatribe ,
I'm not sure what might cause this error, it looks like gradle specific, maybe you can post your question in StackOverflow.
I've tried to search for similar errors, here's one link that might help: gradle/gradle#2860

Also, have you tried cleaning your local gradle cache, the one at C:\Users\<username>\.gradle.
Also, does this happen when you try to build a pure JavaScript application created with CLI (i.e. tns create app1 --js).

@datatribe
Copy link

I traced the problem to the ip address provided for our proxy server. Thanks for your help @rosen-vladimirov - you helped me pinpoint the issue.

@rosen-vladimirov
Copy link
Contributor

I'm so glad you were able to trace the issue. Happy coding!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants