GoogleCloudPlatform / gradle-appengine-plugin

Gradle plugin that provides tasks for uploading, running and managing Google App Engine projects
Apache License 2.0
236 stars 60 forks source link

DevAppServer wrong host for /_ah/api/static/proxy.html #240

Open CrandellWS opened 8 years ago

CrandellWS commented 8 years ago

see google/google-api-javascript-client#175

As suggested at: https://cloud.google.com/appengine/docs/java/tools/devserver#Command_Line_Arguments https://cloud.google.com/tools/android-studio/app_engine/run_test_deploy

When attempting to run the sample running the DevAppServer using Android Studio on pc and accessing via external device, "Chrome://inspect" shows an error connection refused because the usl points to localhost and it should be pointed to the host ip not the client.

This error is only found when the host and client have different localhosts (ie they are different machines).

tried answer at http://stackoverflow.com/a/33316693/1815624 but to no avail, though setting the ip to 0.0.0.0 might help track this: i71wdm amlayl

If I set the ip to the machine's network ip instead of 0.0.0.0 I get different 404 errors than if it was set to localhost.

CrandellWS commented 8 years ago

@loosebazooka can we get a release bump please?

patflynn commented 8 years ago

@loosebazooka should we file this as a bug under Cloud Tools for AS?

On Wed, Mar 30, 2016 at 5:15 AM, William Crandell notifications@github.com wrote:

@loosebazooka https://github.com/loosebazooka can we get a release bump please?

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/GoogleCloudPlatform/gradle-appengine-plugin/issues/240#issuecomment-203338935

loosebazooka commented 8 years ago

we can file a bug to change the template to set it to 0.0.0.0 or at least add a comment there?

loosebazooka commented 8 years ago

@CrandellWS while this is not really related to dev appserver override, you should be able to edit your build.gradle file and set the httpPort in the appengine closure there.

CrandellWS commented 8 years ago

@loosebazooka setting the value to 0.0.0.0 is how I can find the problem but does not fix it.

Or am I misunderstanding?

CrandellWS commented 8 years ago

When using 0.0.0.0 everything works when using a browser on the same machine, regaurdless of browsing to localhost or 10.0.0.10 (as example)

but using a different machine or device that CAN NOT access the devappserver using localhost in the browser address bar and can only access with ip 10.0.0.10. I end up with 404 errors trying to access localhost on the remote machine that is not running the appserver.

let me know if I can clarify or if you want me to make a demo.

I made a gist based on the tutorial in the discription: see -> https://gist.github.com/CrandellWS/05e887ef3a815f2e257d54e4259ac61b

as there is no live app I changed https://gist.github.com/CrandellWS/05e887ef3a815f2e257d54e4259ac61b#file-src_main_webapp_js_appsrc-js-L28 https to http...

the build config is :

// If you would like more information on the gradle-appengine-plugin please refer to the github page
// https://github.com/GoogleCloudPlatform/gradle-appengine-plugin

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.google.appengine:gradle-appengine-plugin:1.9.32'
    }
}

repositories {
    jcenter();
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'

sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

dependencies {
  appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.34'
  compile 'com.google.appengine:appengine-endpoints:1.9.34'
  compile 'com.google.appengine:appengine-endpoints-deps:1.9.34'
  compile 'javax.servlet:servlet-api:2.5'
}

appengine {
  downloadSdk = true
  appcfg {
    oauth2 = true
  }
  endpoints {
    getClientLibsOnBuild = true
    getDiscoveryDocsOnBuild = true
  }
}
CrandellWS commented 8 years ago

by the way the port does not change only the host and I was wrong it is not a 404 error rather a connection refused because there is not a server running on the external machine...

http://**localhost**:8081/_ah/api/static/proxy.html?jsh=... Failed to load resource: net::ERR_CONNECTION_REFUSED

and I am actually using port 8081 for this....

CrandellWS commented 8 years ago

@loosebazooka You see the error when you click the 'Say "Hello" >>' button but not before

loosebazooka commented 8 years ago

I'm not sure I understand, are you trying to access localhost from another machine? That would only reference that machine on which you are trying to reach localhost. Setting address to 0.0.0.0 only makes the app server accessible from other machines. More info : http://stackoverflow.com/questions/7534967/is-there-any-way-to-access-gae-dev-app-server-in-the-local-network

10.0.0.10 appears to be the address of your computer running the appengine application? In which case it should make sense that that's the only way to access it.

The javascript code you're referencing is some special code to detect that you're running the server locally and disable https. Keep in mind that if you're deploying this to app engine (on the cloud), you will need it to be an https address.

So, I guess it makes sense that you can only access it by 10.0.0.10. If you use 10.0.0.10, what breaks?

CrandellWS commented 8 years ago

the problem is the DevAppServer is sending a link for localhost from 10.0.0.10 that should be 10.0.0.10 and not localhost.

So: http://localhost:8081/_ah/api/static/proxy.html?jsh=... Failed to load resource: net::ERR_CONNECTION_REFUSED

Should be: http://10.0.0.10:8081/_ah/api/static/proxy.html?jsh=...

but it is not, hence the problem is only apparent when accessing through a different machine/device/pc whatever...

loosebazooka commented 8 years ago

oh interesting, can you set the httpAddress on the devAppServer to 10.0.0.10 and then launch? I wonder if it's something to do with the endpoints configuration.

CrandellWS commented 8 years ago

same results

CrandellWS commented 8 years ago

hence my assumption that https://github.com/GoogleCloudPlatform/gradle-appengine-plugin/commit/a68b880dee6229ed777147fe7e486ac9efa2d7d5

might fix this issue

loosebazooka commented 8 years ago

you seem to have your javascript loading stuff in two places : https://gist.github.com/CrandellWS/05e887ef3a815f2e257d54e4259ac61b#file-src_main_webapp_index-html-L96

https://gist.github.com/CrandellWS/05e887ef3a815f2e257d54e4259ac61b#file-src_main_webapp_js_appsrc-js-L29

is everything updated correctly here?

On Wed, Mar 30, 2016 at 7:44 PM, William Crandell notifications@github.com wrote:

hence my assumption that a68b880 https://github.com/GoogleCloudPlatform/gradle-appengine-plugin/commit/a68b880dee6229ed777147fe7e486ac9efa2d7d5

might fix this issue

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/GoogleCloudPlatform/gradle-appengine-plugin/issues/240#issuecomment-203687611

CrandellWS commented 8 years ago

yea I had separated the javascript...but for this I put it back and forgot to delete the js file...I updated the gist to clarify https://gist.github.com/CrandellWS/05e887ef3a815f2e257d54e4259ac61b

CrandellWS commented 8 years ago

You are correct that DEV_APPSERVER_DEFAULT_ADDRESS does not fix this, as I had hoped...

@loosebazooka if I can help further let me know, as in the future I will be wanting to test in this manner (using remote devices instead of emulators). Thank you for your time and help. I will check back into this at a later unknown date and time.

loosebazooka commented 8 years ago

Everything I understand about the problem makes it seem like it should work. I'll set up a test and update the bug when I can.

CrandellWS commented 8 years ago

@loosebazooka it would be nice to have another clearly reproduce this, thanks, the easiest way to reproduce this I know, would be to use "Android Studios" set up a project and add a "Google Cloud Module" after you add or import the new module, all you will need to do is adjust the build.config and run it.

    dependencies {
        classpath 'com.google.appengine:gradle-appengine-plugin:1.9.34'
    }

and

dependencies {
  appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.34'
  compile 'com.google.appengine:appengine-endpoints:1.9.34'
  compile 'com.google.appengine:appengine-endpoints-deps:1.9.34'
  compile 'javax.servlet:servlet-api:2.5'
}

Readers please remember to also set the IP and port information as is described elsewhere in this thread.