@chubbyts/chubbyts-http-uwebsockets-bridge
v1.2.2
Published
A uwebsockets req/res http bridge.
Downloads
8
Readme
chubbyts-http-uwebsockets-bridge
Description
A uwebsockets req/res http bridge.
Requirements
- node: 16
- @chubbyts/chubbyts-http-types: ^1.2.3
- uWebSockets.js: github:uNetworking/uWebSockets.js#v20.44.0
Installation
Through NPM as @chubbyts/chubbyts-http-uwebsockets-bridge.
npm i @chubbyts/chubbyts-http-uwebsockets-bridge@^1.2.2
Usage
import {
createServerRequestFactory,
createStreamFromResourceFactory,
createUriFactory,
} from '@chubbyts/chubbyts-http/dist/message-factory';
import { createResponseToUwebsocketsEmitter, createUwebsocketsToServerRequestFactory } from '@chubbyts/chubbyts-http-uwebsockets-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
2024 Dominik Zogg