Giter VIP home page Giter VIP logo

event-server's Introduction

Simplistic nodejs service listens for incoming events and passes them further down to (multiple) WebSocket listeners.

No restriction via roles, only authorization via tokens. This should be used only by your trusted back-end services, not client applications.

The service is split into two servers (listen and broadcast).

Usage

Your project should document the types of events that are passed through this service and what format of data they contain.

How to fire events?

Send HTTP POST /event to the listen server with body:

{
    "event": "<type of event>",
    "data": ...
}

Include relevant data that you want the listener to receive. Include Authorization header with credentials (see below).

Server should respond with:

{ "code": "OK" }

Possible error codes:

  • INVALID_BODY (400)
  • UNAUTHENTICATED (403)
  • AUTH_UNRECOGNIZED_SCHEME (403)

How to listen to events?

Connect via WebSocket to the broadcast server. Then send initialization message:

{
  "authentication": "<credentials>",
  "events": [
    "<type of event to listen to>",
    "<another type of event to listen to>"
  ]
}

events contains types you want to listen to. The server will respond:

{
  "type": "init",
  "code": "OK"
}

Possible error codes:

  • INVALID_SYNTAX
  • INVALID_EVENTS_MISSING
  • AUTH_UNRECOGNIZED_SCHEME
  • UNAUTHENTICATED

Now when an event is fired, you will receive a message:

{
  "type": "event",
  "event": "<type of event>",
  "data": ...
}

Authentication

Send authentication credentials: <scheme> <token>

Currently, only 'Basic' authentication is supported. This works by storing authorized tokens in a file.

Configuration

Auth tokens

Write tokens you want to accept in /tokens/tokens file. Make sure the file has only necessary permissions.

Tokens must be no less than 16 characters long, otherwise they will be ignored.

HTTPS

To enable, provide HTTPS_ENABLE=true environment variable to the service. Create /certs/cert.key and /certs/cert.crt files.

Ports

  • listen - 8080,
  • broadcast - 8081.

Docker

  • production - 11000 and 11001,
  • development - 12000 and 12001.

Development

  1. npm install
  2. Configure
  3. npm start (or npm run docker or npm run dockerd for background)

To run unit tests: npm test. Note: authentication services are currently not tested.

Possible expansions

The project may benefit from additional authentication schemes (e.g. expirable Bearer tokens) and authorization via roles.

event-server's People

Contributors

marius321967 avatar

Watchers

James Cloos avatar  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.