Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/cli/parse-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ const help = function(){
function startServer(options, callback) {
const app = express();
const api = new ParseServer(options);
const sockets = {}
let nextId = 0;
app.use(options.mountPath, api);

var server = app.listen(options.port, callback);
server.on('connection', initializeConnections);
if (options.startLiveQueryServer || options.liveQueryServerOptions) {
let liveQueryServer = server;
if (options.liveQueryPort) {
Expand All @@ -43,8 +46,28 @@ function startServer(options, callback) {
}
ParseServer.createLiveQueryServer(liveQueryServer, options.liveQueryServerOptions);
}

function initializeConnections(socket) {
const socketId = nextId++;
socket.id = socket.id || socketId;
sockets[socketId] = socket;

socket.on('close', (s) => {
delete sockets[s.id];
})
}

function shutConnections() {
for (const socketId in sockets) {
try {
sockets[socketId].destroy()
} catch (e) { }
}
}

var handleShutdown = function() {
console.log('Termination signal received. Shutting down.');
shutConnections();
server.close(function () {
process.exit(0);
});
Expand Down