Validate serverURL on Start (#4204)
* Added basic validation of publicServerURL
* Fixed up 'verifyServerUrl' and added tests
* Use Parse.serverURL instead, general cleanup.
* Test server port moved to 13376
* Removed reconfigureServer calls with simple changing of Parse.serverURL
* changed var to const
* Disabled automatic serverURL verification during testing, moved verification call into app.on('mount') callback, removed setTimeout from verification.
This commit is contained in:
committed by
Florent Vilmart
parent
9745caf9fb
commit
9376b4d04a
@@ -360,8 +360,9 @@ class ParseServer {
|
||||
|
||||
api.use(middlewares.handleParseErrors);
|
||||
|
||||
//This causes tests to spew some useless warnings, so disable in test
|
||||
// run the following when not testing
|
||||
if (!process.env.TESTING) {
|
||||
//This causes tests to spew some useless warnings, so disable in test
|
||||
process.on('uncaughtException', (err) => {
|
||||
if (err.code === "EADDRINUSE") { // user-friendly message for this common error
|
||||
/* eslint-disable no-console */
|
||||
@@ -372,6 +373,10 @@ class ParseServer {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
// verify the server url after a 'mount' event is received
|
||||
api.on('mount', function() {
|
||||
ParseServer.verifyServerUrl();
|
||||
});
|
||||
}
|
||||
if (process.env.PARSE_SERVER_ENABLE_EXPERIMENTAL_DIRECT_ACCESS === '1') {
|
||||
Parse.CoreManager.setRESTController(ParseServerRESTController(appId, appRouter));
|
||||
@@ -413,6 +418,27 @@ class ParseServer {
|
||||
static createLiveQueryServer(httpServer, config) {
|
||||
return new ParseLiveQueryServer(httpServer, config);
|
||||
}
|
||||
|
||||
static verifyServerUrl(callback) {
|
||||
// perform a health check on the serverURL value
|
||||
if(Parse.serverURL) {
|
||||
const request = require('request');
|
||||
request(Parse.serverURL.replace(/\/$/, "") + "/health", function (error, response, body) {
|
||||
if (error || response.statusCode !== 200 || body !== "OK") {
|
||||
/* eslint-disable no-console */
|
||||
console.warn(`\nWARNING, Unable to connect to '${Parse.serverURL}'.` +
|
||||
` Cloud code and push notifications may be unavailable!\n`);
|
||||
if(callback) {
|
||||
callback(false);
|
||||
}
|
||||
} else {
|
||||
if(callback) {
|
||||
callback(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addParseCloud() {
|
||||
|
||||
Reference in New Issue
Block a user