Package Exports
- @logux/server
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@logux/server) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Logux Server 
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.
Documentation: logux/logux
This repository contains Logux server with:
- Framework to write own server.
- Proxy between WebSocket and HTTP server on any other language.
Install
npm install @logux/serverUsage
See documentation for Logux API.
Logux Server as Proxy
const { Server } = require('@logux/server')
const server = new Server(
Server.loadOptions(process, {
controlPassword: 'secret',
subprotocol: '1.0.0',
supports: '0.6.2',
backend: 'http://localhost:3000/logux',
root: __dirname
})
)
server.listen()Logux Server as Framework
const { isFirstOlder } = require('@logux/core')
const { Server } = require('@logux/server')
const server = new Server(
Server.loadOptions(process, {
subprotocol: '1.0.0',
supports: '1.x',
root: __dirname
})
)
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 init (ctx, action, meta) {
const user = await db.loadUser(ctx.params.id)
server.log.add(
{ type: 'USER_NAME', name: user.name },
{ clients: [ctx.clientId] })
)
}
})
server.type('CHANGE_NAME', {
access (ctx, action, meta) {
return action.user === ctx.userId
},
process (ctx, action, meta) {
if (isFirstOlder(lastNameChange(action.user), meta)) {
return db.changeUserName({ id: action.user, name: action.name })
}
}
})
app.listen()