1.2.1 • Published 1 year ago

@chubbyts/chubbyts-uwebsockets-http-bridge v1.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

chubbyts-uwebsockets-http-bridge

CI Coverage Status Infection MSI npm-version

bugs code_smells coverage duplicated_lines_density ncloc sqale_rating alert_status reliability_rating security_rating sqale_index vulnerabilities

Description

A uwebsockets req/res http bridge.

Requirements

Installation

Through NPM as @chubbyts/chubbyts-uwebsockets-http-bridge.

npm i @chubbyts/chubbyts-uwebsockets-http-bridge@^1.2.1

Usage

import {
  createServerRequestFactory,
  createStreamFromResourceFactory,
  createUriFactory,
} from '@chubbyts/chubbyts-http/dist/message-factory';
import { createResponseToUwebsocketsEmitter, createUwebsocketsToServerRequestFactory } from '@chubbyts/chubbyts-uwebsockets-http-bridge/dist/uwebsocket-http';
import { App, HttpRequest, HttpResponse } from 'uWebSockets.js';

const app = ...;

const uwebsocketsToServerRequestFactory = createUwebsocketsToServerRequestFactory(
  createUriFactory(),
  createServerRequestFactory(),
  createStreamFromResourceFactory(),
);

const responseToUwebsocketsEmitter = createResponseToUwebsocketsEmitter();

const host = '0.0.0.0';
const port = 8080;

App()
  .any('/*', async (res: HttpResponse, req: HttpRequest) => {
    // function gets excuted on abort
    // empty function means the request/response gets executed to its end
    res.onAborted(() => {});
    responseToUwebsocketsEmitter(await app(uwebsocketsToServerRequestFactory(req, res)), res);
  })
  .listen(host, port, (listenSocket: unknown) => {
    if (listenSocket) {
      console.log(`Listening to ${host}:${port}`);
    }
  });

Copyright

2023 Dominik Zogg

1.2.0

1 year ago

1.1.1

1 year ago

1.2.1

1 year ago

1.1.0

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago