cudr_slate-collaborative/packages/example/server.js

29 lines
745 B
JavaScript
Raw Normal View History

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