Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routing #552

Open
georeith opened this issue Mar 29, 2023 · 3 comments
Open

Routing #552

georeith opened this issue Mar 29, 2023 · 3 comments
Assignees

Comments

@georeith
Copy link
Collaborator

georeith commented Mar 29, 2023

The problem I am facing

We have multiple types of document with different data in them that have different middleware requirements.

The solution I would like

The ability to set up different middleware routes based on the HTTP path of the original request, query parameters etc.

Alternatives I have considered

Running separate HocusPocus instances for each document type. We do this in some places but this puts more strain on the rest of our deployment infrastructure and is less flexible for taking advantage of our existing resources.

Branching inside middleware blocks but its messy and error prone, everything constantly has to filter the type of document before it can do anything with it.

Additional context

There's some thought to be had around how this would work with multiplexing and subdocuments as they are likely to be documents of different types and may have different storage needs etc.

Some of our views have access to documents of multiple types and it would be nice if they can benefit from multiplexing also.

@janthurau
Copy link
Collaborator

@georeith I'm not sure I understand what you mean by middleware 🤔 Are you talking about onChange etc. hooks that need to run for certain documents only (e.g. those prefixed like article.123)?

@georeith
Copy link
Collaborator Author

georeith commented Mar 29, 2023

@georeith I'm not sure I understand what you mean by middleware 🤔 Are you talking about onChange etc. hooks that need to run for certain documents only (e.g. those prefixed like article.123)?

Yes by middleware I mean extensions really. E.g., something like this on setup:

Server.configure({
    extensions: {
        path1: [],
        path2: [],
    }
})

instead of:

Server.configure({
    extensions: []
})

@chenyuncai
Copy link
Collaborator

@georeith

You can create multiple instance to handle the different request.

const server1 = new Hocuspocus({})
const server2 = new Hocuspocus({})

and in your connection event of websocketServer route the handler

if (req.url === '/documents') {
    server1.handleConnection(ws, req)
  } else if (req.url === '/share-data') {
    server2.handleConnection(ws, req)
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants