-
Notifications
You must be signed in to change notification settings - Fork 0
/
hocuspocus.mjs
54 lines (47 loc) · 1.32 KB
/
hocuspocus.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"use strict";
import * as Sentry from "@sentry/node";
const dsn = process.env.SENTRY_PUBLIC_DSN || process.env.SENTRY_DSN
if (dsn) {
console.log("sentry dsn: ", dsn);
Sentry.init({dsn});
}
import { Server } from "@hocuspocus/server";
import { SQLite } from "@hocuspocus/extension-sqlite";
import { Logger } from "@hocuspocus/extension-logger";
const url = (process.env.APP_URL || `https://${process.env.CANONICAL_HOST}`) + '/api/hocuspocus'
const port = (process.env.RAILS_ENV == 'production') ? 5000 : 4444
console.log("hocuspocus auth url: ", url);
const server = Server.configure({
port: port,
timeout: 30000,
debounce: 5000,
maxDebounce: 30000,
quiet: true,
name: "hocuspocus",
extensions: [
new Logger(),
new SQLite({database: ''}), // anonymous database on disk
],
async onAuthenticate(data) {
const { token, documentName } = data;
const response = await fetch(url, {
method: 'POST',
body: JSON.stringify({ user_secret: token, document_name: documentName }),
headers: { 'Content-type': 'application/json; charset=UTF-8' },
})
if (response.status != 200) {
throw new Error("Not authorized!");
} else {
return true;
}
},
});
if (dsn) {
try {
server.listen();
} catch (e) {
Sentry.captureException(e);
}
} else {
server.listen();
}