You might try using:

'//' + window.location.host + '/_ah/api'

instead. That should direct to whatever host/port is running the app (with the proper protocol).