Skip to content
Build own Logux server or make proxy between WebSocket and HTTP backend on any language
Branch: master
Clone or download
Latest commit 39526b8 Apr 25, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test Fix support for unknownAction and unknownChannel back-end commands Apr 18, 2019
.editorconfig Initial commit Oct 26, 2016
.gitignore Fix Node.js 12 support Apr 25, 2019
.npmignore Fix Node.js 12 support Apr 25, 2019
.travis.yml Remove Travis CI microoptimization Apr 25, 2019
CHANGELOG.md Release 0.3.1 version Apr 18, 2019
LICENSE Initial commit Oct 26, 2016
README.md Fix Markdown Apr 9, 2019
allowed-meta.js Fix imports in JSDoc Apr 9, 2019
base-server.js Refactor to async/await (#58) Apr 24, 2019
bind-backend-proxy.js
context.js
create-reporter.js Remove Prometheus to Pro package Apr 10, 2019
filtered-node.js Refactor to async/await (#58) Apr 24, 2019
force-promise.js Update dependencies Jun 22, 2018
human-formatter.js
index.js Update code style Jul 30, 2018
package.json Clean up dictionary Apr 26, 2019
parse-node-id.js Add clientId Nov 26, 2018
promisify.js Update dependencies Jun 22, 2018
server-client.js Refactor to async/await (#58) Apr 24, 2019
server.js Refactor to async/await (#58) Apr 24, 2019
start-control-server.js
yarn.lock Update dependencies Apr 25, 2019

README.md

Logux Server Cult Of Martians

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.
Sponsored by Evil Martians

Install

npm install @logux/server

Usage

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()
You can’t perform that action at this time.