0.2.3 • Published 4 months ago

@vlcn.io/ws-server v0.2.3

Weekly downloads
-
License
-
Repository
github
Last release
4 months ago

@vlcn.io/ws-server

Basic Setup

WebSocket sync server. Setups is pretty straightforward and involves:

  1. Defining a config
  2. Attaching the websocket server to your http server

Define Config

const wsConfig = {
  // Folder where database files should be placed
  dbFolder: "./dbs",
  // Folder that contains `.sql` schema files to apply to databases
  schemaFolder: "./src/schemas",
  // The path(s) that the websocket server should listen to
  pathPattern: /\/sync/,
};

Attach to Server

import * as http from "http";
const app = express(); // or fastify or nest or whatever
const server = http.createServer(app);

const wsConfig = {
  dbFolder: "./dbs",
  schemaFolder: "./src/schemas",
  pathPattern: /\/sync/,
};

// Attach here:
attachWebsocketServer(server, wsConfig);

server.listen(PORT, () =>
  console.log("info", `listening on http://localhost:${PORT}!`)
);

LiteFS Setup

Note: LiteFS support is not production ready. It currently does not handle LiteFS primary node failover.

If you want to replicate your DB on the backend via LiteFS you can specify a few additional configuration options.

const wsConfig = {
  dbFolder: "./dbs",
  schemaFolder: "./src/schemas",
  pathPattern: /\/sync/,
  // appName is REQUIRED for LiteFS setups
  appName: process.env.FLY_APP_NAME
};

const WRITE_FORWARD_PORT = 9000;
const dbFactory = await createLiteFSDBFactory(WRITE_FORWARD_PORT, wsConfig);
dbCache = attachWebsocketServer(
  server,
  wsConfig,
  dbFactory,
  new FSNotify(wsConfig)
);

// Set up a service to receive forwarded writes
createLiteFSWriteService(WRITE_FORWARD_PORT, wsConfig, dbCache);
0.2.3

4 months ago

0.2.1

5 months ago

0.2.0

5 months ago

0.2.2

5 months ago

0.2.0-next.4

5 months ago

0.2.0-next.3

6 months ago

0.2.0-next.2

6 months ago

0.2.0-next.1

6 months ago

0.2.0-next.0

6 months ago

0.1.2

8 months ago

0.1.2-next.1

8 months ago

0.1.2-next.0

8 months ago

0.1.1

8 months ago

0.1.0

8 months ago

0.1.0-next.21

8 months ago

0.1.0-next.20

9 months ago

0.1.0-next.19

9 months ago

0.1.0-next.18

9 months ago

0.1.0-next.17

9 months ago

0.1.0-next.16

9 months ago

0.1.0-next.15

9 months ago

0.1.0-next.14

9 months ago

0.1.0-next.13

9 months ago

0.1.0-next.12

9 months ago

0.1.0-next.11

9 months ago

0.1.0-next.2

9 months ago

0.1.0-next.0

9 months ago