2020-05-10 13:50:12 +00:00
|
|
|
const { SocketIOConnection } = require('@slate-collaborative/backend')
|
2019-10-27 20:50:01 +00:00
|
|
|
const express = require('express')
|
|
|
|
|
2020-05-10 13:50:12 +00:00
|
|
|
const defaultValue = [
|
|
|
|
{
|
|
|
|
type: 'paragraph',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
text: 'Hello collaborator!'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2019-10-27 20:50:01 +00:00
|
|
|
const PORT = process.env.PORT || 9000
|
2019-10-05 08:44:49 +00:00
|
|
|
|
2019-10-28 16:56:12 +00:00
|
|
|
const server = express()
|
|
|
|
.use(express.static('build'))
|
|
|
|
.listen(PORT, () => console.log(`Listening on ${PORT}`))
|
|
|
|
|
2019-10-05 08:44:49 +00:00
|
|
|
const config = {
|
2019-10-27 12:43:12 +00:00
|
|
|
entry: server, // or specify port to start io server
|
2019-10-05 08:44:49 +00:00
|
|
|
defaultValue,
|
2020-05-10 13:50:12 +00:00
|
|
|
saveFrequency: 2000,
|
2019-10-05 08:44:49 +00:00
|
|
|
onAuthRequest: async (query, socket) => {
|
|
|
|
// some query validation
|
|
|
|
return true
|
|
|
|
},
|
|
|
|
onDocumentLoad: async pathname => {
|
2020-05-10 13:50:12 +00:00
|
|
|
// request initial document ValueJSON by pathnme
|
2019-10-05 08:44:49 +00:00
|
|
|
return defaultValue
|
|
|
|
},
|
2020-05-10 13:50:12 +00:00
|
|
|
onDocumentSave: async (pathname, doc) => {
|
2019-10-05 08:44:49 +00:00
|
|
|
// save document
|
2020-05-10 13:50:12 +00:00
|
|
|
// console.log('onDocumentSave', pathname, doc)
|
2019-10-05 08:44:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-10 13:50:12 +00:00
|
|
|
const connection = new SocketIOConnection(config)
|