Skip to content

Migrating to mLab + Google App Engine #3247

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
HoraceBury opened this issue Dec 16, 2016 · 32 comments
Closed

Migrating to mLab + Google App Engine #3247

HoraceBury opened this issue Dec 16, 2016 · 32 comments

Comments

@HoraceBury
Copy link

HoraceBury commented Dec 16, 2016

I have followed the instructions at https://parse.com/migration#server but I cannot get my local Parse instance to connect to my mLab database. I'm using the mongodb connection string with appropriate username and password. I can also get my local dashboard to talk to my local mongo instance via the local Parse server, but not the mLab.

Is there a step missing or some security element I might be missing?

(Sorry for the vagueness!)

@otymartin
Copy link

otymartin commented Dec 16, 2016

@HoraceBury can you post your server.js code

@HoraceBury
Copy link
Author

I'm actually trying to host the example: https://github.com/ParsePlatform/parse-server-example

But the index.js from that is, of course, very similar to the server.js, so here it is (slightly obfuscated):

// Example express application adding the parse-server module to expose Parse
// compatible API routes.

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

var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI || "mongodb://username:[email protected]:59767/mymongodb";

if (!databaseUri) {
  console.log('DATABASE_URI not specified, falling back to localhost.');
}

var api = new ParseServer({
  databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || 'MUx82uLFnvDB---GCuH2wxRFhh0P',
  masterKey: process.env.MASTER_KEY || 'ybe8Mh3gWK---nHC3OnRqfj3U', //Add your master key here. Keep it secret!
  serverURL: process.env.SERVER_URL || 'https://localhost:1337/parse',  // Don't forget to change to https if needed
  liveQuery: {
    classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
  }
});
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
// If you wish you require them, you can set them as options in the initialization above:
// javascriptKey, restAPIKey, dotNetKey, clientKey

var app = express();

// Serve static assets from the /public folder
app.use('/public', express.static(path.join(__dirname, '/public')));

// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);

// Parse Server plays nicely with the rest of your web routes
app.get('/', function(req, res) {
  res.status(200).send('I dream of being a website.  Please star the parse-server repo on GitHub!');
});

// There will be a test page available on the /test path of your server url
// Remove this before launching your app
app.get('/test', function(req, res) {
  res.sendFile(path.join(__dirname, '/public/test.html'));
});

var port = process.env.PORT || 1337;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
    console.log('parse-server-example running on port ' + port + '.');
});

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

@otymartin
Copy link

@HoraceBury in mlab.com did you create a user for your database? Not the mlab login, but a user for that specific database you created in mlab?
screen shot 2016-12-16 at 12 55 20 pm

@HoraceBury
Copy link
Author

Yes, in the connection string where it says "mongodb://username:password" those are actually my DB's credentials.

When connecting from my local machine with the mongo shell that connStr is fine. Which is why I think I'm missing something in the overall process.

@otymartin
Copy link

if (!databaseUri) {
  console.log('DATABASE_URI not specified, falling back to localhost.');
} // Try and log the databaseURI here with the else statement

@HoraceBury
Copy link
Author

Yep, absolutely no worry about the connStr reaching the ParseServer constructor.

Am I correct in thinking that the connection string is the only thing the ParseServer needs to be able to connect to the mLab database?

@HoraceBury
Copy link
Author

I have even tried to very straightforward and simple directions here:

https://github.com/ParsePlatform/parse-server/wiki/Quick-Start

This does not work either. Is there a security permission which needs to be set or provided?

@otymartin
Copy link

To be honest I'm stumped, I never encountered this before. Will update if I figure out a possible cause.
Did you make sure your parse server is up to date? And are you running it locally? eg. node server.js in your commandline?

@HoraceBury
Copy link
Author

How do I specify nodeserver.js on the command line? The Quick Start doesn't mention that but does guide on how to run the server from a single CLI command.

@otymartin
Copy link

otymartin commented Dec 17, 2016

@HoraceBury thats how I run my local server. i just navigate to the folder where my server.js file is and type node server.js command into my terminal on mac and it starts running. when you run it that way post the logs here if it spits out any errors

@HoraceBury
Copy link
Author

When you do that are you running it against a DB on mLab?

@HoraceBury
Copy link
Author

From the error log:

{"error":{"code":200,"message":"bad or missing username"},"level":"error","message":"Error generating response. ParseError { code: 200, message: 'bad or missing username' }","timestamp":"2016-12-16T20:56:06.156Z"}
{"error":{"code":200,"message":"bad or missing username"},"level":"error","message":"Error generating response. ParseError { code: 200, message: 'bad or missing username' }","timestamp":"2016-12-16T20:56:07.769Z"}

I'm not sure which username that is referring to. It can't be the MongoDB database username as that is included in the connection string.

@otymartin
Copy link

@HoraceBury can you try two things.
javascript databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
// In that line, remove the local mongodb and use just the databaseUri.
and in mlab.com, check if your database user is read only (mine is false)

@HoraceBury
Copy link
Author

My database user is not read-only.

I am only using the databaseUri.

Same result - this is what I've been doing since the start.

@HoraceBury
Copy link
Author

When I configure server.js with the credentials and run it with 'node server.js' the response in postman includes this in the header: X-Powered-By →Express

The body is:
{
"results": []
}

I'm running this under: /nodejs-docs-samples/appengine/parse-server

The full server.js (lightly obfuscated) is this:

/**

  • Copyright 2016, Google, Inc.
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at
  • http://www.apache.org/licenses/LICENSE-2.0
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.
    */

'use strict';

// [START app]
const express = require('express');
const nconf = require('nconf');
const ParseServer = require('parse-server').ParseServer;
const path = require('path');

nconf.argv().env().file({ file: 'config.json' });

const app = express();

const parseServer = new ParseServer({
databaseURI: 'mongodb://user:[email protected]:59767/game',
cloud: path.join(__dirname, '/cloud/main.js'),
appId: 'MUx82uLFnvDBujwoZ-------cYLGCuH2wxRFhh0P',
masterKey: 'ybe8Mh3gW----YpInhYJXFH4wBcunHC3OnRqfj3U',
fileKey: 'e9047ef7-27c0------9194-a154278a93cc',
serverURL: 'http://localhost:8080/'
});

// Mount the Parse API server middleware to /parse
app.use(process.env.PARSE_MOUNT_PATH || '/parse', parseServer);

app.get('/', (req, res) => {
res.status(200).send('Hello, world!');
});

const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(App listening on port ${PORT});
console.log('Press Ctrl+C to quit.');
});
// [END app]

@HoraceBury
Copy link
Author

My local firewall is off and as mentioned connecting to mLab db via the Mongo CLI works fine.

@HoraceBury
Copy link
Author

Hitting http://localhost:8080/parse in a browser gets me:
{"error":"unauthorized"}

The above response in postman is achieved using the X-Parse-Application-Id and X-Parse-Master-Key headers with the values from the server.js above.

@flovilmart
Copy link
Contributor

Does your username or password for mLab contains special characters? Like :, @,; etc...

@HoraceBury
Copy link
Author

HoraceBury commented Dec 20, 2016

Nope, it is simply:
dev:dev
As in username:password

@HoraceBury
Copy link
Author

I am even trying to go through this tutorial to get a new local instance of Parse setup, pointing at a new, empty DB on mLab:

https://www.raywenderlich.com/128313/parse-server-tutorial

I'm running into the authentication problem, here, because (with a new Parse and new DB) I don't have an application ID or master key.

@flovilmart
Copy link
Contributor

You can use any random string for applicationId and masterKey, keep your masterKey private, never share it

@HoraceBury
Copy link
Author

But does the mLab DB care about that or is it just for use between the client and Parse?

@Muesly
Copy link

Muesly commented Dec 20, 2016

I have managed to get Parse on App Engine and mLab working, and I thought I maybe able to help but nothing stands out.

I remember serverURL causing me some issues. Is it set to https://localhost:1337/parse? Try http rather than https.

@otymartin
Copy link

@Muesly good call, @HoraceBury I see you are using environment variables, can you confirm that your databaseURI: databaseUri && process.env.SERVER_URL are correctly formatted? Both in server and client. Your server URL should have .../parse at the end.

@HoraceBury
Copy link
Author

@muesely Yes, the serverURL is set to exactly that.

@Muesly
Copy link

Muesly commented Dec 21, 2016

Try http?

@HoraceBury
Copy link
Author

@otymartin I can confirm that the config.json and server.js are the same and in correct format.

When I connect to the database from the CLI I get this message:

MongoDB shell version v3.4.0
connecting to: mongodb://user:[email protected]:41098/mydb
MongoDB server version: 3.2.11
WARNING: shell and server versions do not match

I am using the latest version of mongo on my local box. The mongo shell lets me execute commands against the mLab DB. Could there be something I am missing, like needing to downgrade to a previous version of the shell? Seems odd that the latest version of Mongo Shell and mLab are mismatched.

@HoraceBury
Copy link
Author

Both config.json and server.js are set up for http.

@HoraceBury
Copy link
Author

@Muesly @otymartin Would one of you be prepared to Skype with me on this, please? I know, it's a big ask, but it would be hugely helpful. (Sorry to ask!)

@Muesly
Copy link

Muesly commented Dec 21, 2016

Sure, happy to help if I can :)

@otymartin
Copy link

Yea go with @Muesly if he can't i'll give it a go. But if you find a problem & solution please document it here for future reference

@HoraceBury
Copy link
Author

Thank you guys, I really appreciate it. I'm incommunicado for the next 24hrs at least as I'm travelling but if you're about Friday my Skype is my username on here.

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

5 participants