Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move WebSocket path under document-level prefix. (#315)
Originally, Y-Sweet returned just a WebSocket URL. Now, we return both a `baseUrl` (which is the base used for the `update` / `as-update` endpoints), as well as a `url` which is a WebSocket URL. I want to deprecate `url`, but that means that we need to be able to construct the WebSocket URL deterministically from a `baseUrl`. This is not currently possible, because it depends on how the server is set up: - When running in `doc-serve` mode, we put the websocket server under `/ws` relative to the `baseUrl` - When running as a standalone server (`y-sweet serve`), we put the doc-relative endpoints under `/d/:doc_id/` but the WebSocket endpoint at the top level. This PR makes `y-sweet serve` consistent with `doc-serve`, by making the WebSocket URL relative to `/d/:doc_id/`. Since the y-websocket provider also appends the doc ID, this means the URL contains the doc ID twice, which we check for equality. (Our own provider will not have this problem). In order to not break users who manually construct the WebSocket URL, the old-style URL still works. The `url` returned by the `auth` endpoint points to the new `/d/:doc_id/ws` server. Before we update the client to construct the WebSocket URL from `baseUrl` (removing the need to return `url`), we will have to make this change with the cloudflare worker as well. Existing tests cover this, but I also ran locally and confirmed that the URL is constructed as expected as a sanity check.
- Loading branch information