mirror of
https://github.com/cudr/slate-collaborative.git
synced 2024-10-27 20:34:06 +00:00
0fd9390a99
Update Slate-Collaboration to be compatible with Slate 0.5x versions.
40 lines
894 B
JavaScript
40 lines
894 B
JavaScript
const { SocketIOConnection } = require('@slate-collaborative/backend')
|
|
const express = require('express')
|
|
|
|
const defaultValue = [
|
|
{
|
|
type: 'paragraph',
|
|
children: [
|
|
{
|
|
text: 'Hello collaborator!'
|
|
}
|
|
]
|
|
}
|
|
]
|
|
|
|
const PORT = process.env.PORT || 9000
|
|
|
|
const server = express()
|
|
.use(express.static('build'))
|
|
.listen(PORT, () => console.log(`Listening on ${PORT}`))
|
|
|
|
const config = {
|
|
entry: server, // or specify port to start io server
|
|
defaultValue,
|
|
saveFrequency: 2000,
|
|
onAuthRequest: async (query, socket) => {
|
|
// some query validation
|
|
return true
|
|
},
|
|
onDocumentLoad: async pathname => {
|
|
// request initial document ValueJSON by pathnme
|
|
return defaultValue
|
|
},
|
|
onDocumentSave: async (pathname, doc) => {
|
|
// save document
|
|
// console.log('onDocumentSave', pathname, doc)
|
|
}
|
|
}
|
|
|
|
const connection = new SocketIOConnection(config)
|