First off, you want to enable logs for your EB environment and look at the Node.js and nginx logs in your CloudWatch Log Groups. The logs will tell you more about the actual issue, otherwise this is just tapping in the dark.
If you look at the Parse Server Example repo index.js file, there are some notable entries:
const databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
const config = {
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'myAppId',
masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed
};
const mountPath = process.env.PARSE_MOUNT || '/parse';
const port = process.env.PORT || 1337;
The following parameters are currently not set correctly:
-
databaseURI
: this is not set in your environment, because you have set DATABASE_URIDATABASE_URI
instead of just DATABASE_URI
; this means Parse Server most likely cannot connect to a database
-
serverURL
: this is not set correct in your environment, and unless the exposed port in EB environment is exactly 1337, I think this cannot be set via an environment variable. Because parse server is mounted on the port assigned by EB (process.env.PORT
), but you do not know which port that is when you set the environment variable.
Itâs important to understand that Parse Server has 2 URL parameters:
-
serverURL
: used by Parse Server when it needs to call itself
-
publicServerURL
: used by Parse Server when it needs to tell external parties how it can be reached, from outside of your EB environment
The internal serverURL
usually looks like http://localhost:1337/parse
, but in your case you do not know whether the port is 1337. The EB environment tells Node.js to which port it routes incoming requests via the process.env.PORT
variable. So you would need to compose the serverURL
in index.js
(that means modifying the example repo) to make it look like this:
const serverURL = `http://localhost${process.env.PORT}/parse`;
The same goes for the publicServerURL
, which would look like this:
const publicServerURL = `http://ec2-161-189-119-69.cn-northwest-1.compute.amazonaws.com.cn/parse`;
Note that you do not have to include the port in the publicServerURL
, because EB is automatically routing any request to that URL to the assigned port that is the port in process.env.PORT
, on which Parse Server is mounted. Also note that this is not using TLS (https protocol), so all traffic is transferred unencrypted, which you may not want, thinking about login passwords, etc.
I think we really need to update the AWS instructions in the parse-server-example repo, to make this easier.