运行 Express.js + Parse Server 并尝试使用“https”JS 库在 Parse API 路由上配置 HTTPS。
代码片段
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);
重新创建的步骤
安装正确的库
使用:Node(4.5),https(1.0.0)
运行“node index.js”
预期成绩
服务器应在 HTTPS 端口上顺利启动
https://mydomainhere:4444/parse
实际结果
~/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)
环境设置
使用:Node(4.5)、https(1.0.0)、parse-server(“2.2.22”)、Linux Centos
答案1
虽然这个问题很久以前就被问到了,但由于没有合适的答案,我正尝试为未来的读者回答这个问题。
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.');
});
答案2
我遇到了同样的问题并报告了解析服务器的问题。
Flovilmart 对此提供了帮助,并发现正确的方法是为 https 服务器声明一个新变量。在您的示例中,您将使用:
var https = require('https');
....
var httpsServer = https.createServer(config.certificate,app).listen(port,function() {
console.log('parse-server-example running on port ' + port + '.');
});
这将启用 Live Query 实时服务器
ParseServer.createLiveQueryServer(httpsServer);
您可以在此处看到完整的对话:https://github.com/ParsePlatform/parse-server/issues/3165#event-881061654