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

'Unable to connect to Parse API' since enabling HTTPS #411

Closed
omairvaiyani opened this issue Feb 14, 2016 · 36 comments
Closed

'Unable to connect to Parse API' since enabling HTTPS #411

omairvaiyani opened this issue Feb 14, 2016 · 36 comments

Comments

@omairvaiyani
Copy link
Contributor

We've added SSL to our AWS-hosted ParseServer, but are receiving this error when running any CloudFunction:

"error": {
    "code": 100,
    "message": "XMLHttpRequest failed: \"Unable to connect to the Parse API\""
  }

We've updated our serverUrl to have https. After a bit of digging around, I ran into ParseServer/middlewares.js#handleParseHeaders, where I logged the req.protocol. It says the protocol is http, even though the requests are sent with https.

Just for more info - we have not yet enabled SSL on the mongolabs database. GET requests work fine.

@gfosco
Copy link
Contributor

gfosco commented Feb 14, 2016

Need a bit more context. Where is the code running / what type of client is making the request and gets this error?

@omairvaiyani
Copy link
Contributor Author

Sure.

I'm using a chrome plugin called Postman to make the requests. Our ParseServer was created using this AWS-ParseServer guide. Here's the main part of our index.js code:


...

// parseServer
var parseServer = new ParseServer({
    appId: process.env.APP_ID,
    masterKey: process.env.MASTER_KEY,
    databaseURI: process.env.DATABASE_URI,
    cloud: __dirname + '/cloud/main.js',
    serverURL: process.env.SERVER_URL + process.env.PARSE_MOUNT,
    facebookAppIds: process.env.FACEBOOK_APP_IDS,
    fileKey: process.env.FILE_KEY
});

// Node app
var app = express();

// CORS
app.use(cors());

// Server path and setup
app.use(process.env.PARSE_MOUNT, parseServer);

...

The error occurs when I make a https POST request to any cloud function. By changing the request and serverUrl to http, the error goes away.

@ivan-liljeqvist
Copy link

Any progress? same issue

@ivan-liljeqvist
Copy link

@daaku @gfosco

@omairvaiyani
Copy link
Contributor Author

We ended up setting serverUrl protocol as http. So whilst our client to server data is still sent via SSL, any self calls made by our server will be unsecure - at least until the issue resolves. Though I must say, we have not tried re-checking this issue since 2.0.7.

@ivan-liljeqvist
Copy link

@omairvaiyani I wonder if it's because of MongoLab

@omairvaiyani
Copy link
Contributor Author

I looked into the code at the time and am pretty sure it didn't have anything to do with MongoLab. From what I remember, the REST request made by the server never reached back to the server - the HTTP response code was 0. This might indicate some sort of firewall block?

I think the more long-term fix would be to question why a REST call is being made by the server to itself? Should the code not be triggered locally?

@drew-gross
Copy link
Contributor

@omairvaiyani we are still discussing the best model for how to handle this issue in the long term. In the meantime, you should be able to use localhost in your serverURL to avoid having unencrypted requests on the public internet.

@gfosco gfosco closed this as completed Feb 26, 2016
@r2DoesInc
Copy link

I moved everything over to be running off of https://localhost, install a self singed cert, but my dashboard is not loading the server. I can use the same usrl to interact with my cloud code, and can see the "unauthorized" message at the url on the browser, so i know thats the correct url for the server. the dashboard still errors with, POST https://localhost/msz/parse/serverInfo net::ERR_CONNECTION_REFUSED

My dashboard loads the server if i change it back to the external url, however the cloud code fails to interact with the database.

@Spacelapp
Copy link

+1
Only the parse cloud code cannot connect to the server via https...

@omairvaiyani
Copy link
Contributor Author

@Spacelapp We've set our serverUrl to 'localhost:port' to counter-act this.

@Spacelapp
Copy link

I already tried this...but when I use a cloud function in my iOS app I get this error: [Error]: { code = 100; message = "XMLHttpRequest failed: {}"; } (Code: 141, Version: 1.13.0)

@omairvaiyani
Copy link
Contributor Author

Could you show us your config parameters in node for ParseServer?

@Spacelapp
Copy link

Sure:
var server = new ParseServer({ databaseURI: 'mongodb://USER:PASSWORD@localhost:27017/database', cloud: __dirname + '/cloud/main.js', appId: 'APP_ID', masterKey: 'MASTERKEY', serverURL: 'localhost:3000/parse', oauth: { facebook: { appIds: "FB_APPID" } } });

@omairvaiyani
Copy link
Contributor Author

Where is your server deployed? AWS often defaults to port 8081 and perhaps the url needs to be http://localhost:port/mount as I vaguely remember seeing the error without http://.

@Spacelapp
Copy link

selfhosted (express)

@Spacelapp
Copy link

this should be reopened again...It's a bug, and it's not fixed with the newest version of parse-server

@Spacelapp
Copy link

Well it only works, if I setup http & https server at the same time...not really a good solution

@r2DoesInc
Copy link

If you refer to my comments earlier, you need to have your server setup
over HTTPS. The serverUrl variable in your dash config should point to your
servers local address.

This way, any direct communication to your server from the app is done over
the HTTPS connection. The dashboard itself only communicates with the
server over the local IP.

On Sun, Apr 17, 2016, 3:43 PM Lukas Kovar notifications@github.com wrote:

Well it only works, if I setup http & https server at the same time...not
really a good solution


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#411 (comment)

@r2DoesInc
Copy link

FWIW I also had issues without the http:// on my serverUrl. Mine looks ike SERVER_URL=http://localhost:1337/parse

@w3care25
Copy link

I am using self hosted parse-server and not able to use cloud functions since I have enabled HTTPS, if I revert it back to HTTP it works as expected.

Also he problem is only with those cloud function which have Parse.Query, if i create a function simply return "Hello" as response it works on both HTTP and HTTPS.

I am getting following error message when run a cloud function which have Parse.Query code.

{ "code": 141, "error": "XMLHttpRequest failed: "Unable to connect to the Parse API"--100"}

can anyone tell me how can I fix this?

@omairvaiyani
Copy link
Contributor Author

Have you tried the answers above you? Set SERVER_URL as http://localhost:[port]/[mount], even if your protocol is HTTPS.

@w3care25
Copy link

yes I have tried that, but it doesn't work for me.

@w3care25
Copy link

I have fixed this issue. Reason behind this is that node rejects unauthorized TLS.
so just put
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

in my parse server instance file.

@ndnguru
Copy link

ndnguru commented May 23, 2016

Here is what worked for me:

Environment: app deployed on AWS, with the load balancer configured for HTTPS

On the server side, where you configure parse-server, use HTTP in the serverURL configuration parameter. On the client side, use HTTPS when you initialize the Parse app/library.

My theory is that the load balancer is terminating HTTPS traffic, so from the load balancer to the instance, it might be HTTP traffic. In this case, if the parse-server is configured for a HTTPS URL, then it might be trying to listen on a different port or something screwy like that?

I'm not an expert on how the AWS architecture works under the hood, so my rationale might be way off or downright incorrect. If anyone can explain why this would work, please chime in.

@david-koch-pro
Copy link

david-koch-pro commented May 23, 2016

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

I am using Elastic Beanstalk as server and can I use this? May I put this in index.js?
parse-community/parse-server-example#199

@natanrolnik
Copy link
Contributor

In case anyone is still having this issue, I had the same and managed to fix by changing my Server URL from https://myapp.com/parse to https://www.myapp.com/parse

@Hitabis
Copy link

Hitabis commented Dec 6, 2016

Thanks @natanrolnik! I resolved the same behavior (in development) changing form
http://docker:1337/parse to http://localhost:1337/parse

There is something wrong with the serverURL. The issue only occurred in beforeSave trigger for me. @gfosco please reopen the issue.

@flovilmart
Copy link
Contributor

The serverURL is used in cloud code, it should 99% of the time be http://localhost:[port]/[mountPath].

If you're using https in node, i recommend you start a http sever as well listening on any different port from the https server and pass the host parameter to 127.0.0.1. This will allow communications only from the server itself.

@francisjervis
Copy link

francisjervis commented Jan 7, 2017

I just encountered this issue. @flovilmart's response is correct for development (ie running the server locally), but the way I was able to fix it for running on Heroku was by using http instead of https in the serverUrl parameter. @w3care25's fix likely addresses the same issue, tho this is probably a bug.

@alex-vasenin
Copy link

alex-vasenin commented Jan 20, 2017

Just had this issue. For me the problem was solved by replacing cert.pem with fullchain.pem certificate (both from Let's Encrypt) in https server options. I found the issue by running wget https://mypublicdomain.com:1337/parse which surprisingly returned ERROR: cannot verify mypublicdomain.com's certificate even though web browser didn't have any problem. Solution was inspired by certbot/certbot#2026

@WebRence
Copy link

We also had this problem for migrating existing Mobile App from parse.com to self Hosted Parse server on AWS but as mentioned by someone in this thread we simply changed the URL from HTTPs to HTTP on load balancer and used HTTPs only on client side this seems working.

@nsnick
Copy link

nsnick commented Jan 28, 2017

I am still having this problem. I had the parse server set up and both the iOS app and the parse dashboard were able to connect over http. I then changed the AWS load balancer to accept client side traffic on port 443 and set a valid SSL certificate. I changed the uri in the parse dashboard and the parse dashboard can connect fine still. I changed the uri in the iOS app and the iOS app cannot connect. If I enable port 80 on the AWS load balancer, the iOS app can connect fine regardless of what the uri is set to in the iOS app. The parse URL is currently defined as https://parse-server.com:443/parse in the iOS app. The parse iOS library seems to be ignoring both the "https" and the "443". Inside the parse-server I have serverURL: process.env.SERVER_URL || 'https://parse-server.com/parse'

@johndoehelloworld
Copy link

Was there ever a solution for this? I tried https, http, parse app URL, and localhost in serverURL – none worked. Thoughts anyone?

@francisjervis
Copy link

francisjervis commented Mar 28, 2017

The way I got it to work was by adding

import os
os.environ["PARSE_API_ROOT"] = "http://db.myserver.co/parse"

to settings.py

@leew
Copy link

leew commented Jun 26, 2017

My Application is using the perfect storm, SSL, File Storage, Cloud code.

This meant that I couldn't set the server url env variable to localhost as this broke the file urls that were output.

After investigating the function code, I saw the the credentials are set before ever function execution, so
I ended up setting Parse.serverURL at the start of my functions that used Parse.query

This "solved" the issue for me, I added this as an additional env var as above PARSE_API_URL

var ParseApi = process.env.PARSE_API_URL

Parse.Cloud.define("name", function(request, response)
{
	Parse.serverURL = ParseApi;

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

No branches or pull requests