-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add hocuspocus server along side our other node stuff
- Loading branch information
1 parent
382c599
commit ca123c6
Showing
4 changed files
with
49 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"use strict"; | ||
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' | ||
console.log("hocuspocus auth url: ", url); | ||
|
||
const server = Server.configure({ | ||
port: 7700, | ||
timeout: 30000, | ||
debounce: 5000, | ||
maxDebounce: 30000, | ||
quiet: false, | ||
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; | ||
} | ||
}, | ||
}); | ||
|
||
server.listen(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,14 @@ | |
"author": "Robert Guthrie <[email protected]>", | ||
"license": "AGPLv3", | ||
"engines": { | ||
"node": "16.x" | ||
"node": "20.x" | ||
}, | ||
"dependencies": { | ||
"@sentry/node": "^7.0.0", | ||
"@hocuspocus/extension-database": "^2.13.5", | ||
"@hocuspocus/extension-logger": "^2.13.5", | ||
"@hocuspocus/extension-sqlite": "^2.13.5", | ||
"@hocuspocus/server": "^2.13.5", | ||
"@sentry/node": "^6.19.6", | ||
"@sentry/tracing": "^6.19.6", | ||
"dotenv": "^16.0.1", | ||
"redis": "^4.1.0", | ||
|
@@ -21,9 +25,7 @@ | |
"nodemon": "^2.0.16" | ||
}, | ||
"scripts": { | ||
"start": "node --harmony index.js", | ||
"start-dev": "node_modules/.bin/nodemon index.js", | ||
"lint": "eslint --ext js ./", | ||
"lint-fix": "eslint --fix --ext js ./" | ||
"start": "node index.js", | ||
"hocuspocus": "node hocuspocus.mjs" | ||
} | ||
} |