logux/docs

server to use defined subprotocol?

Closed this issue · 3 comments

I was reading across the docs and wondering if the server is supposed to use the subprotocol that was defined in the previous step, rather than a static string? As we do with the client

defined as part of the project

Create `api/index.ts` with subprotocol version (client-server API).
```ts
export const SUBPROTOCOL = '1.0.0'
```

imported for server but afterwards not used for

Create `index.ts` with:
```js
import { Server } from '@logux/server'
import { SUBPROTOCOL } from '../api/index.js'
const server = new Server(
Server.loadOptions(process, {
subprotocol: '1.0.0',
supports: '1.x',
fileUrl: import.meta.url
})
)

because the client does

Open `src/index.ts` and add:
```tsx
import { CrossTabClient, badge, badgeEn, log } from '@logux/client'
import { badgeStyles } from '@logux/client/badge/styles'
import { SUBPROTOCOL } from '../api'
const client = new CrossTabClient({
prefix: 'appName',
server: process.env.NODE_ENV === 'development'
? 'ws://localhost:31337'
: 'wss://logux.example.com',
subprotocol: SUBPROTOCOL,
userId: 'anonymous', // TODO: We will fill it in Authentication recipe
token: '' // TODO: We will fill it in Authentication recipe
})

ai commented

Server needs subprotocol to mark actions created on this server by server.log.add(action) or server.process(action).

Later you can work with old actions from log knowing what server on server created this action. It is useful in big production projects with many changes.

Does it answer your question? Feel free to ask extra details if needed.

sorry, maybe me asking this way made the conversation go this way.

I'm mainly wondering, if the SUBPROTOCOL const that is imported shouldn't be used instead of the static '1.0.0' that is currently displayed as part of the docs.

as in: should this be changed in the docs to show a coherent usage of the configuration.

ai commented

Got it! Yes, we should use const. Fixed 3a53dde