Skip to content

Parse Server livequery on AWS (Websocket error 403) #3635

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

Closed
lyonlionng opened this issue Mar 14, 2017 · 14 comments
Closed

Parse Server livequery on AWS (Websocket error 403) #3635

lyonlionng opened this issue Mar 14, 2017 · 14 comments

Comments

@lyonlionng
Copy link

lyonlionng commented Mar 14, 2017

Issue Description

I am using currently on a project trying to make a chat system using parse server livequery. I am using AWS's Parse Server by Bitnami AMI to create a new instance. And i did the setups exactly as i did on my localhost. However whenever i run my ionic 2 application, it will show the websocket error as shown below.

WebSocket connection to 'ws://ec2-xxxx.ap-southeast-1.compute.amazonaws.com/parse' failed: Error during WebSocket handshake: Unexpected response code: 403

Steps to reproduce

  1. Create a instance of Parse Server by Bitnami
  2. Create a new ionic 2 application(any template)
  3. run "ionic serve --lab"
  4. inspect your console

Expected Results

There shouldnt be a websocket error and the livequery will auto reload and show on my chat system.

Actual Outcome

It shows the error and whenever i send a text to a user, the other party does not receive and updates until he backs out one screen and went back the same page.

Environment Setup

  • Server

    • parse-server version : 2.3.1
    • Operating System: Linux and Windows 10
    • Hardware: dont think this would be a problem...
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): AWS
  • Database

    • MongoDB version: 3.2.11
    • Storage engine: MMAPv1
    • Hardware: nil
    • Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): mLab
@flovilmart
Copy link
Contributor

Did you configure Parse-server correctly to start the liveQuery server?

@lyonlionng
Copy link
Author

lyonlionng commented Mar 14, 2017

This is my current server code...

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var mailgun = require('mailgun-js');
var app = express();
// Specify the connection string for your mongodb database
// and the location to your Parse cloud code
var api = new ParseServer({
databaseURI: "xxxxx",
cloud: "./cloud/main.js",//"./node_modules/parse-server/lib/cloud-code/Parse.Cloud.js",
appId: "xxxxx",
masterKey: "xxxxx",
fileKey: "xxxxx",
serverURL: 'http://ec2-xxxxx.ap-southeast-1.compute.amazonaws.com:80/parse',

// Subscription for Livequery
liveQuery: {
classNames: ["CareRecipient", "Patient", "Message", "ContactList", "ChatMessage"]
},

// Mailgun Configuration
emailAdapter: {
module: 'parse-server-simple-mailgun-adapter',
options: {
fromAddress: "xxxxx",
domain: "xxxx.mailgun.org",
apiKey: "key-xxxx"
}
}
});
// Serve the Parse API on the /parse URL prefix
app.use('/parse', api);

var port = 1337;
app.listen(port, function() {
console.log('parse-server running on port ' + port);
});

//Parse Dashboard
var ParseDashboard = require('parse-dashboard');
var dashboard = new ParseDashboard({
apps: [
{
appName: "xxx",
appId: "xxx",
masterKey: "xxx",
fileKey: "xxxx",
production: true,
serverURL: 'http://ec2-xxx.ap-southeast-1.compute.amazonaws.com:80/parse'
}
]
});

var allowInsecureHTTP = true;

// Serve the Mailgun on /email URL prefix
app.get ('/email', function (req, res){
res.status(200).send('Email has been sent!');
var api_key = 'key-xxx';
var domain = 'xxx.mailgun.org';

var mailgun = require('mailgun-js')({apiKey: api_key, domain: domain});

var data = {
from: 'Witzu <postmaster@xxx.mailgun.org>',
to: 'xxx@gmail.com',
subject: 'Welcome toxxx!',
text: 'Please confirm your email! New Mailgun :)'
};

mailgun.messages().send(data, function (error, body) {
console.log(body);
});

});

// Serve the Parse Dashboard on the /parsedashboard URL prefix
app.use('/', dashboard);

var portdash = 4040;
app.listen(portdash, function() {
console.log('parse-dashboard running on port ' + portdash);
});
/var port = 1337;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
console.log('parse-server running on port ' + port + '.');
});
/
ParseServer.createLiveQueryServer(app);

@flovilmart
Copy link
Contributor

Are you running on Elastic beanstalk or a naked instance? Are you using ELB? Do you have any server logs when running with VERBOSE=1 ?

@lyonlionng
Copy link
Author

i used the AWS Parse Server by Bitnami AMI to create a new instance. Could this be the issue? and no im not using ELB. No server logs either...

@flovilmart
Copy link
Contributor

I have no idea what that particular image does, it may as it may not.

@lyonlionng
Copy link
Author

lyonlionng commented Mar 14, 2017

Okay, lets say start from the beginning, i launched the instance and the serve.js was like this:

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var app = express();
// Specify the connection string for your mongodb database
// and the location to your Parse cloud code
var api = new ParseServer({
databaseURI: "mongodb://root:B7cBoeHrFiEx@127.0.0.1:27017/bitnami_parse",
cloud: "./node_modules/parse-server/lib/cloud-code/Parse.Cloud.js",
appId: "xxx",
masterKey: "xxx",
fileKey: "xxx",
serverURL: 'http://ec2-xxx.ap-southeast-1.compute.amazonaws.com:80/parse'
});
// Serve the Parse API on the /parse URL prefix
app.use('/parse', api);

var port = 1337;
app.listen(port, function() {
console.log('parse-server running on port ' + port);
});

//Parse Dashboard
var ParseDashboard = require('parse-dashboard');
var dashboard = new ParseDashboard({
apps: [
{
appName: "My Bitnami Parse API",
appId: "xxx",
masterKey: "xxx",
fileKey: "xxx",
production: true,
serverURL: 'http://ec2-xxx.ap-southeast-1.compute.amazonaws.com:80/parse'
}
],
users: [
{
user: "user",
pass: "xxx"
}
], useEncryptedPasswords: true
});

var allowInsecureHTTP = true;

// Serve the Parse Dashboard on the /parsedashboard URL prefix
app.use('/', dashboard);

var portdash = 4040;
app.listen(portdash, function() {
console.log('parse-dashboard running on port ' + portdash);
});

What would be the code to enable livequery? (just want to make sure im right)

@flovilmart
Copy link
Contributor

flovilmart commented Mar 14, 2017

From the docs, you'd need:

// Initialize a LiveQuery server instance, app is the express app of your Parse Server
let httpServer = require('http').createServer(app);
httpServer.listen(port);
var parseLiveQueryServer = ParseServer.createLiveQueryServer(httpServer);

I see also something, you're using twice app with calling listen on 2 different ports. That won't work.

you should have:

var serverApp = express();

var api = new ParseServer({...});
serverApp.use('/parse', api);
var port = 1337;
/*
// !!! Important, this should be removed
// That will prevent proper init from the LQ server
app.listen(port, function() {
  console.log('parse-server running on port ' + port);
});
*/

var httpServer = require('http').createServer(serverApp);
httpServer.listen(port);
var parseLiveQueryServer = ParseServer.createLiveQueryServer(httpServer);

var dashboardApp = express();
var ParseDashboard = require('parse-dashboard');
var dashboard = new ParseDashboard({...});
var allowInsecureHTTP = true;

// Serve the Parse Dashboard on the /parsedashboard URL prefix
dashboardApp.use('/', dashboard);

var portdash = 4040;
dashboardApp.listen(portdash, function() {
  console.log('parse-dashboard running on port ' + portdash);
});

@lyonlionng
Copy link
Author

i have tried your answer but it doesnt work either. If i were to start afresh and not use Bitnami's AMI, will it work? and do you have a guide somewhere to teach me the steps? im kinda new to parse...

@flovilmart
Copy link
Contributor

The docs link I provided should give the most information about it.
I would not recommend you 'start-over' as that may not solve your issue.

I'm not sure what responds with 403 on your liveQuery client, perhaps missing keys in the JS-SDK.

@lyonlionng
Copy link
Author

One thing to take note is that if i host it on heroku, it works 100%. Only only AWS the livequery is not working. I am so confused. I have searched many sites regarding issue and have not come to a solution

@flovilmart
Copy link
Contributor

flovilmart commented Mar 14, 2017

So if it works on heroku, that's not an issue with parse-server itself, or your configuration, but with the way you're deployed on AWS.

I recommend you stick with heroku for now, and keep exploring why AWS is reluctant with you., We have many reports of people having successfully deployed to AWS, however we don't provide provider specific help.

@LilMoke
Copy link

LilMoke commented Nov 16, 2018

I was wondering if anyone has a solution to this issue with AWS. flovilmart made mention that people have successfully set up live query on AWS, but unfortunately it looks like no-one has shared the details. If anyone has successfully set this up on AWS would you be so kind as to share the secret? LOL, but really any help with this issue would be greatly appreciated. I am getting the same 403 error and have followed the steps in every article I could find on the issue with no luck.

@dplewis
Copy link
Member

dplewis commented Nov 16, 2018

@LilMoke Check out this guide

https://github.com/SoBump/ParseLiveQueryHelp/blob/master/guide.md

@LilMoke
Copy link

LilMoke commented Nov 16, 2018

Awesome thanks so much. I took a quick look and I think it told me my problem. I was using a classic old balancer and my nginx file was slightly wrong. Thanks again, I will try it shortly.

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

4 participants