chore: Move to Typescript (#2783)
This PR moves the entire project to Typescript. Due to the ~1000 ignores this will lead to a messy codebase for a while, but the churn is worth it – all of those ignore comments are places that were never type-safe previously. closes #1282
This commit is contained in:
41
server/services/collaboration.ts
Normal file
41
server/services/collaboration.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import http from "http";
|
||||
import url from "url";
|
||||
import { Server } from "@hocuspocus/server";
|
||||
import invariant from "invariant";
|
||||
import Koa from "koa";
|
||||
import WebSocket from "ws";
|
||||
import AuthenticationExtension from "../collaboration/authentication";
|
||||
import LoggerExtension from "../collaboration/logger";
|
||||
import PersistenceExtension from "../collaboration/persistence";
|
||||
import TracingExtension from "../collaboration/tracing";
|
||||
|
||||
export default function init(app: Koa, server: http.Server) {
|
||||
const path = "/collaboration";
|
||||
const wss = new WebSocket.Server({
|
||||
noServer: true,
|
||||
});
|
||||
const hocuspocus = Server.configure({
|
||||
extensions: [
|
||||
new AuthenticationExtension(),
|
||||
// @ts-expect-error ts-migrate(2322) FIXME: Type 'Persistence' is not assignable to type 'Exte... Remove this comment to see the full error message
|
||||
new PersistenceExtension(),
|
||||
new LoggerExtension(),
|
||||
// @ts-expect-error ts-migrate(2322) FIXME: Type 'Persistence' is not assignable to type 'Exte... Remove this comment to see the full error message
|
||||
new TracingExtension(),
|
||||
],
|
||||
});
|
||||
server.on("upgrade", function (req, socket, head) {
|
||||
if (req.url && req.url.indexOf(path) > -1) {
|
||||
const documentName = url.parse(req.url).pathname?.split("/").pop();
|
||||
invariant(documentName, "Document name must be provided");
|
||||
|
||||
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'Duplex' is not assignable to par... Remove this comment to see the full error message
|
||||
wss.handleUpgrade(req, socket, head, (client) => {
|
||||
hocuspocus.handleConnection(client, req, documentName);
|
||||
});
|
||||
}
|
||||
});
|
||||
server.on("shutdown", () => {
|
||||
hocuspocus.destroy();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user