Join chat

Creating Logux Proxy

In this guide, we will create the Logux proxy between WebSocket and your back-end server.

If you like Node.js and want the best performance, you can try to move business logic directly to Logux Server. Or you can keep high-performance parts in Logux Server and send others to the back-end HTTP server.

Creating the Project

Install Node.js (version 10.0 or later).

Create a directory for a project. We will use server-logux name.

mkdir server-logux
cd server-logux

Create package.json with:

{
  "name": "server-logux",
  "private": true,
  "scripts": {
    "start": "node index.js"
  }
}

Install Logux Server:

  • npm i @logux/server

    Create index.js with:

    const { Server } = require('@logux/server')
    
    const server = new Server(
      Server.loadOptions(process, {
        subprotocol: '1.0.0',
        supports: '1.x',
        root: __dirname
      })
    )
    
    server.listen()

    Create .env file. Put this file to .gitignore. Set your local back-end server URL and secret:

    LOGUX_BACKEND=http://localhost:3000/
    LOGUX_CONTROL_SECRET=secret

    The proxy is ready. You can start it with:

  • npm start

    To stop the server press Command+. on Mac OS X and Ctrl+C on Linux and Windows.

    The proxy will send the user’s authentication request, Logux subscriptions, and actions to http://localhost:3000/logux. Your back-end can send actions to the client by sending an HTTP request to http://localhost:31338.

    Back-end Server

    Now we need to prepare back-end to receive requests from Logux proxy server.

  • logux-django package adds Back-end Protocol support to Django.

    Go to your Django application folder:

    cd ../django-server

    Install logux-django:

    pip install logux-django

    Add path(r'logux/', include('logux.urls')), into your urls.py

    Sets Logux settings in your settings.py:

    # Logux settings: https://logux.io/guide/starting/proxy-server/
    LOGUX_CONTROL_SECRET = "secret"
    LOGUX_URL = "http://localhost:31338"
    LOGUX_AUTH_FUNC = (lambda user_id, token: True) if DEBUG is True else None