Skip to content
This repository has been archived by the owner on Jul 10, 2022. It is now read-only.

chubbyjs-legacy/chubbyjs-uwebsockets-psr-http-message-bridge

Repository files navigation

chubbyjs-uwebsockets-psr-http-message-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.js req/res psr-htt-message bridge.

Requirements

Installation

Through NPM as @chubbyjs/chubbyjs-uwebsockets-psr-http-message-bridge.

npm i @chubbyjs/chubbyjs-uwebsockets-psr-http-message-bridge@1.3.1 \
    @chubbyjs/chubbyjs-http-message@1.1.1

Usage

import PsrRequestFactory from '@chubbyjs/chubbyjs-uwebsockets-psr-http-message-bridge/dist/PsrRequestFactory';
import ResponseFactory from '@chubbyjs/chubbyjs-http-message/dist/Factory/ResponseFactory';
import ServerRequestFactory from '@chubbyjs/chubbyjs-http-message/dist/Factory/ServerRequestFactory';
import StreamFactory from '@chubbyjs/chubbyjs-http-message/dist/Factory/StreamFactory';
import UriFactory from '@chubbyjs/chubbyjs-http-message/dist/Factory/UriFactory';
import UwebsocketResponseEmitter from '@chubbyjs/chubbyjs-uwebsockets-psr-http-message-bridge/dist/UwebsocketResponseEmitter';
import { HttpRequest, HttpResponse } from 'uWebSockets.js';

const responseFactory = new ResponseFactory();

const psrRequestFactory = new PsrRequestFactory(
    new ServerRequestFactory(),
    new UriFactory(),
    new StreamFactory()
);

const uwebsocketResponseEmitter = new UwebsocketResponseEmitter();

require('uWebSockets.js')
    .App()
    .any('/*', (res: HttpResponse, req: HttpRequest) => {
        const serverRequest = psrRequestFactory.create(req, res);
        const response = responseFactory.createResponse(200);

        serverRequest.getBody().pipe(response.getBody());

        uwebsocketResponseEmitter.emit(response, res);
    })
    .listen('0.0.0.0', 8080, (listenSocket: unknown) => {
        if (listenSocket) {
            console.log('Listening to port 0.0.0.0:8080');
        }
    });

Copyright

Dominik Zogg 2021

About

A uWebSockets.js req/res psr-htt-message bridge.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published