Skip to content

Commit

Permalink
add hocuspocus server along side our other node stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
robguthrie committed Jul 17, 2024
1 parent 382c599 commit ca123c6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 12 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/publish-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ jobs:
HAVESECRET: ${{ secrets.DOCKER_USERNAME }}
steps:
- name: Check out the repo
uses: actions/checkout@v2
uses: actions/checkout@v3
if: env.HAVESECRET != null

- name: Log in to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
uses: docker/login-action@v2
if: env.HAVESECRET != null
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
uses: docker/metadata-action@v4
if: env.HAVESECRET != null
with:
images: loomio/loomio_channel_server

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
uses: docker/build-push-action@v4
if: env.HAVESECRET != null
with:
context: .
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FROM node:14
RUN apt-get update -qq && apt-get install -y build-essential sudo apt-utils
FROM node:20

WORKDIR /app
ADD . /app
Expand Down
36 changes: 36 additions & 0 deletions hocuspocus.mjs
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();
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}

0 comments on commit ca123c6

Please sign in to comment.