Giter Site home page Giter Site logo

vladbrok / logux-server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from logux/server

0.0 0.0 0.0 4.04 MB

Build your own Logux server or make a proxy between a WebSocket and an HTTP backend in any language

Home Page: https://logux.io/

License: MIT License

JavaScript 37.20% TypeScript 60.53% HTML 2.27%

logux-server's Introduction

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.

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

Logux Server as Proxy

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

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()

logux-server's People

Contributors

ai avatar okonet avatar aleksandrsl avatar euaaaio avatar dependabot[bot] avatar artmnv avatar andriibieriezhnoi avatar ertrzyiks avatar ngalaiko avatar pavlokovalov avatar chafilin avatar erictheswift avatar bijela-gora avatar stereobooster avatar polemius avatar yevs avatar vladbrok avatar ambientlight avatar dsalahutdinov avatar pustovalov avatar nickmitin avatar mavrin avatar neruchev avatar xamgore avatar morozred avatar gbezyuk avatar devgru avatar sairus2k avatar mattomanka avatar semenovdl avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.