cudr_slate-collaborative/packages/example/server.js

40 lines
894 B
JavaScript
Raw Normal View History

const { SocketIOConnection } = require('@slate-collaborative/backend')
2019-10-27 20:50:01 +00:00
const express = require('express')
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,
saveFrequency: 2000,
2019-10-05 08:44:49 +00:00
onAuthRequest: async (query, socket) => {
// some query validation
return true
},
onDocumentLoad: async pathname => {
// request initial document ValueJSON by pathnme
2019-10-05 08:44:49 +00:00
return defaultValue
},
onDocumentSave: async (pathname, doc) => {
2019-10-05 08:44:49 +00:00
// save document
// console.log('onDocumentSave', pathname, doc)
2019-10-05 08:44:49 +00:00
}
}
const connection = new SocketIOConnection(config)