Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/logux/server
Build your own Logux server or make a proxy between a WebSocket and an HTTP backend in any language
https://github.com/logux/server
Last synced: 4 days ago
JSON representation
Build your own Logux server or make a proxy between a WebSocket and an HTTP backend in any language
- Host: GitHub
- URL: https://github.com/logux/server
- Owner: logux
- License: mit
- Created: 2016-10-26T15:50:53.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2024-10-18T15:24:32.000Z (26 days ago)
- Last Synced: 2024-10-28T07:16:03.321Z (17 days ago)
- Language: TypeScript
- Homepage: https://logux.org/
- Size: 4.08 MB
- Stars: 454
- Watchers: 13
- Forks: 108
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Logux Server [![Cult Of Martians][cult-img]][cult]
Logux is a new way to connect client and server. Instead of sending
HTTP requests (e.g., AJAX and GraphQL) it synchronizes log of operations
between client, server, and other clients.* **[Guide, recipes, and API](https://logux.org/)**
* **[Issues](https://github.com/logux/logux/issues)**
and **[roadmap](https://github.com/orgs/logux/projects/1)**
* **[Projects](https://logux.org/guide/architecture/parts/)**
inside Logux ecosystemThis repository contains Logux server with:
* Framework to write own server.
* Proxy between WebSocket and HTTP server on any other language.[cult-img]: http://cultofmartians.com/assets/badges/badge.svg
[cult]: http://cultofmartians.com/done.html### Logux Server as Proxy
```js
import { fileURLToPath } from 'url'const server = new Server(
Server.loadOptions(process, {
controlSecret: 'secret',
subprotocol: '1.0.0',
supports: '0.6.2',
backend: 'http://localhost:3000/logux',
fileUrl: import.meta.url
})
)server.listen()
```### Logux Server as Framework
```js
import { fileURLToPath } from 'url'
import { isFirstOlder } from '@logux/core'
import { dirname } from 'path'
import { Server } from '@logux/server'const server = new Server(
Server.loadOptions(process, {
subprotocol: '1.0.0',
supports: '1.x',
fileUrl: import.meta.url
})
)server.auth(async ({ userId, token }) => {
const user = await findUserByToken(token)
return !!user && userId === user.id
})server.channel('user/:id', {
access (ctx, action, meta) {
return ctx.params.id === ctx.userId
},
async load (ctx, action, meta) {
const user = await db.loadUser(ctx.params.id)
return { type: 'USER_NAME', name: user.name }
}
})server.type('CHANGE_NAME', {
access (ctx, action, meta) {
return action.user === ctx.userId
},
resend (ctx, action, meta) {
return { channel: `user/${ ctx.userId }` }
},
async process (ctx, action, meta) {
if (isFirstOlder(lastNameChange(action.user), meta)) {
await db.changeUserName({ id: action.user, name: action.name })
}
}
})server.listen()
```[documentation]: https://logux.org/