Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
CollabServer.start = (app = {}, options = {}) => {
// We merge the options defined by the user
CollabServer.options = {
...defaultOptions,
...options,
};
const server = http.createServer(app);
let db = null;
if (CollabServer.options.db.type === 'mongo') {
db = CollabServer.options.db.url
? ShareDBMongo(CollabServer.options.db.url)
: {};
console.log('CollabServer: Using MongoDB adapter');
} else {
console.log(
'CollabServer: No Database specified, falling back to In Memory'
);
}
// Create the ShareDB backend (that will need to be exported)
ShareDB.types.register(RichText.type);
CollabServer.backend = new ShareDB({ db });
// Create the Websocket server
new WebSocket.Server({ server }).on('connection', function(ws) {
CollabServer.backend.listen(new WebsocketJSONStream(ws));
console.log('New socket client on CollabServer instance');
exec(`mongo ${MONGO_DB} --eval "db.dropDatabase();"`, () => {
mongo = shareDbMongo(MONGO_URL, { allowAllQueries: true })
backend = racer.createBackend({ db: mongo })
resolve()
})
})