feat: Asynchronous initialization of Parse Server (#8232)
BREAKING CHANGE: This release introduces the asynchronous initialization of Parse Server to prevent mounting Parse Server before being ready to receive request; it changes how Parse Server is imported, initialized and started; it also removes the callback `serverStartComplete`; see the [Parse Server 6 migration guide](https://github.com/parse-community/parse-server/blob/alpha/6.0.0.md) for more details (#8232)
This commit is contained in:
@@ -50,16 +50,19 @@ const { VolatileClassesSchemas } = require('../lib/Controllers/SchemaController'
|
||||
const mongoURI = 'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase';
|
||||
const postgresURI = 'postgres://localhost:5432/parse_server_postgres_adapter_test_database';
|
||||
let databaseAdapter;
|
||||
let databaseURI;
|
||||
// need to bind for mocking mocha
|
||||
|
||||
if (process.env.PARSE_SERVER_TEST_DB === 'postgres') {
|
||||
databaseURI = process.env.PARSE_SERVER_TEST_DATABASE_URI || postgresURI;
|
||||
databaseAdapter = new PostgresStorageAdapter({
|
||||
uri: process.env.PARSE_SERVER_TEST_DATABASE_URI || postgresURI,
|
||||
uri: databaseURI,
|
||||
collectionPrefix: 'test_',
|
||||
});
|
||||
} else {
|
||||
databaseURI = mongoURI;
|
||||
databaseAdapter = new MongoStorageAdapter({
|
||||
uri: mongoURI,
|
||||
uri: databaseURI,
|
||||
collectionPrefix: 'test_',
|
||||
});
|
||||
}
|
||||
@@ -149,49 +152,33 @@ let server;
|
||||
let didChangeConfiguration = false;
|
||||
|
||||
// Allows testing specific configurations of Parse Server
|
||||
const reconfigureServer = (changedConfiguration = {}) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (server) {
|
||||
return server.close(() => {
|
||||
server = undefined;
|
||||
reconfigureServer(changedConfiguration).then(resolve, reject);
|
||||
});
|
||||
}
|
||||
try {
|
||||
let parseServer = undefined;
|
||||
didChangeConfiguration = Object.keys(changedConfiguration).length !== 0;
|
||||
const newConfiguration = Object.assign({}, defaultConfiguration, changedConfiguration, {
|
||||
serverStartComplete: error => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
Parse.CoreManager.setRESTController(RESTController);
|
||||
resolve(parseServer);
|
||||
}
|
||||
},
|
||||
mountPath: '/1',
|
||||
port,
|
||||
});
|
||||
cache.clear();
|
||||
ParseServer.start(newConfiguration).then(_parseServer => {
|
||||
parseServer = _parseServer;
|
||||
parseServer.expressApp.use('/1', err => {
|
||||
console.error(err);
|
||||
fail('should not call next');
|
||||
});
|
||||
server = parseServer.server;
|
||||
server.on('connection', connection => {
|
||||
const key = `${connection.remoteAddress}:${connection.remotePort}`;
|
||||
openConnections[key] = connection;
|
||||
connection.on('close', () => {
|
||||
delete openConnections[key];
|
||||
});
|
||||
});
|
||||
});
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
const reconfigureServer = async (changedConfiguration = {}) => {
|
||||
if (server) {
|
||||
await new Promise(resolve => server.close(resolve));
|
||||
server = undefined;
|
||||
return reconfigureServer(changedConfiguration);
|
||||
}
|
||||
didChangeConfiguration = Object.keys(changedConfiguration).length !== 0;
|
||||
const newConfiguration = Object.assign({}, defaultConfiguration, changedConfiguration, {
|
||||
mountPath: '/1',
|
||||
port,
|
||||
});
|
||||
cache.clear();
|
||||
const parseServer = await ParseServer.startApp(newConfiguration);
|
||||
server = parseServer.server;
|
||||
Parse.CoreManager.setRESTController(RESTController);
|
||||
parseServer.expressApp.use('/1', err => {
|
||||
console.error(err);
|
||||
fail('should not call next');
|
||||
});
|
||||
server.on('connection', connection => {
|
||||
const key = `${connection.remoteAddress}:${connection.remotePort}`;
|
||||
openConnections[key] = connection;
|
||||
connection.on('close', () => {
|
||||
delete openConnections[key];
|
||||
});
|
||||
});
|
||||
return parseServer;
|
||||
};
|
||||
|
||||
// Set up a Parse client to talk to our test API server
|
||||
@@ -423,6 +410,7 @@ global.defaultConfiguration = defaultConfiguration;
|
||||
global.mockCustomAuthenticator = mockCustomAuthenticator;
|
||||
global.mockFacebookAuthenticator = mockFacebookAuthenticator;
|
||||
global.databaseAdapter = databaseAdapter;
|
||||
global.databaseURI = databaseURI;
|
||||
global.jfail = function (err) {
|
||||
fail(JSON.stringify(err));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user