Skip to content

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

Description

@omairvaiyani

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.

Activity

  1. gfosco commented on Feb 14, 2016

    @gfosco
    Contributor

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

  2. omairvaiyani commented on Feb 14, 2016

    @omairvaiyani
    ContributorAuthor

    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.

  3. ivan-liljeqvist commented on Feb 25, 2016

    @ivan-liljeqvist

    Any progress? same issue

  4. ivan-liljeqvist commented on Feb 25, 2016

    @ivan-liljeqvist
  5. omairvaiyani commented on Feb 25, 2016

    @omairvaiyani
    ContributorAuthor

    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.

  6. ivan-liljeqvist commented on Feb 25, 2016

    @ivan-liljeqvist

    @omairvaiyani I wonder if it's because of MongoLab

  7. omairvaiyani commented on Feb 25, 2016

    @omairvaiyani
    ContributorAuthor

    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?

  8. drew-gross commented on Feb 25, 2016

    @drew-gross
    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.

  9. r2DoesInc commented on Mar 13, 2016

    @r2DoesInc

    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.

  10. Spacelapp commented on Apr 17, 2016

    @Spacelapp

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

  11. omairvaiyani commented on Apr 17, 2016

    @omairvaiyani
    ContributorAuthor

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

  12. Spacelapp commented on Apr 17, 2016

    @Spacelapp

    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)

  13. omairvaiyani commented on Apr 17, 2016

    @omairvaiyani
    ContributorAuthor

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

  14. Spacelapp commented on Apr 17, 2016

    @Spacelapp

    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" } } });

  15. 7 remaining items

  16. omairvaiyani commented on May 21, 2016

    @omairvaiyani
    ContributorAuthor

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

  17. w3care25 commented on May 21, 2016

    @w3care25

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

  18. w3care25 commented on May 23, 2016

    @w3care25

    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.

  19. ndnguru commented on May 23, 2016

    @ndnguru

    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.

  20. david-koch-pro commented on May 23, 2016

    @david-koch-pro

    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

  21. natanrolnik commented on Jun 27, 2016

    @natanrolnik
    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

  22. Hitabis commented on Dec 6, 2016

    @Hitabis

    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.

  23. flovilmart commented on Dec 6, 2016

    @flovilmart
    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.

  24. francisjervis commented on Jan 7, 2017

    @francisjervis

    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.

  25. alex-vasenin commented on Jan 20, 2017

    @alex-vasenin

    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

  26. WebRence commented on Jan 20, 2017

    @WebRence

    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.

  27. nsnick commented on Jan 28, 2017

    @nsnick

    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'

  28. johndoehelloworld commented on Mar 28, 2017

    @johndoehelloworld

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

  29. francisjervis commented on Mar 28, 2017

    @francisjervis

    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

  30. leew commented on Jun 26, 2017

    @leew

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions