0

Running Express.js + Parse Server and trying to configure HTTPS on the Parse API route with the 'https' JS library.

  • Code snippet

    var https = require('https');
    ....
    https.createServer(config.certificate,app).listen(port,function() {
    console.log('parse-server-example running on port ' + port + '.');
    });
    // This will enable the Live Query real-time server
    ParseServer.createLiveQueryServer(https);
    
  • Steps to recreate

    1. Install the proper libs

      Using: Node (4.5), https (1.0.0)

    2. Run "node index.js"

  • Expected results

    Server should start with no problems running on an HTTPS port https://mydomainhere:4444/parse

  • Actual outcome

    ~/parse/node_modules/parse-server/lib/ParseServer.js:401
    throw err;
    ^
    TypeError: this._server.once is not a function
    at new WebSocketServer (~/parse/node_modules/parse-server/node_modules/ws/lib/WebSocketServer.js:78:18)
    at new ParseWebSocketServer (~/parse/node_modules/parse-server/lib/LiveQuery/ParseWebSocketServer.js:26:13)
    at new ParseLiveQueryServer (~/parse/node_modules/parse-server/lib/LiveQuery/ParseLiveQueryServer.js:103:33)
    at Function.createLiveQueryServer (~/parse/node_modules/parse-server/lib/ParseServer.js:429:14)
    at Object. (~/parse/parse.js:63:13)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    
  • Environment setup

    Using: Node (4.5), https (1.0.0), parse-server ( "2.2.22"), Linux Centos

techraf
  • 4,243
  • 8
  • 29
  • 44
user378809
  • 1
  • 1
  • 2

2 Answers2

2

Although this question was asked long ago, I am trying to answer this question for the future readers as no appropriate answer was posted.

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var app = express();
var fs = require('fs');

var api = new ParseServer({
    databaseURI: 'mongodb://user:pass@localhost:27017/parse', // Connection string for your MongoDB database
    appId: 'your app id',
    masterKey: 'your app master key', // Keep this key secret!
    serverURL: 'https://localhost:1337/parse' // Don't forget to change to https if needed
});

var options = {
    key: fs.readFileSync('/etc/letsencrypt/live/example.com/privkey.pem'),
    cert: fs.readFileSync('/etc/letsencrypt/live/example.com/fullchain.pem')
};

// Serve the Parse API on the /parse URL prefix
app.use('/parse', api);

var httpsServer = require('https').createServer(options,app);

httpsServer.listen(1337, function() {
    console.log('parse-server-example running on port 1337.');
});
avro3030
  • 21
  • 4
  • Welcome to Serverfault and thanks for this answer! You could make this even more useful by explaining it a little. – Esa Jokinen Aug 13 '17 at 16:32
  • I got error: Error: error:0B080074:x509 certificate routines:X509_check_private_key:key values mismatch How to generate certificates? I have .key certificates – Janserik Dec 10 '18 at 13:33
  • I generate certificates with letsencrypt and I didn't know which file it needed in the cert field: fullchain.pem Thanks!! – Andrea Sica Jun 22 '20 at 11:33
0

I had the same problem and reported an issue with parse-server.

Flovilmart helped with that and found out that the right way to do that is to declare a new variable for the https server. In your example you would use:

var https = require('https');
....
var httpsServer = https.createServer(config.certificate,app).listen(port,function() {
console.log('parse-server-example running on port ' + port + '.');
});

This will enable the Live Query real-time server ParseServer.createLiveQueryServer(httpsServer);

you can see the full conversation here: https://github.com/ParsePlatform/parse-server/issues/3165#event-881061654

serverNewbie
  • 55
  • 1
  • 7
Muvimotv
  • 101
  • 2