@chubbyjs/chubbyjs-node-psr-http-message-bridge

A node req/res psr-htt-message bridge.

Usage no npm install needed!

<script type="module">
  import chubbyjsChubbyjsNodePsrHttpMessageBridge from 'https://cdn.skypack.dev/@chubbyjs/chubbyjs-node-psr-http-message-bridge';
</script>

README

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

Requirements

Installation

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

npm i @chubbyjs/chubbyjs-node-psr-http-message-bridge@1.3.0 \
    @chubbyjs/chubbyjs-http-message@1.1.1

Usage

import NodeResponseEmitter from '@chubbyjs/chubbyjs-node-psr-http-message-bridge/dist/NodeResponseEmitter';
import PsrRequestFactory from '@chubbyjs/chubbyjs-node-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 { createServer, IncomingMessage, ServerResponse } from 'http';

const responseFactory = new ResponseFactory();

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

const nodeResponseEmitter = new NodeResponseEmitter();

const server = createServer(async (req: IncomingMessage, res: ServerResponse) => {
    const serverRequest = psrRequestFactory.create(req);
    const response = responseFactory.createResponse(200);

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

    nodeResponseEmitter.emit(response, res);
});

server.listen(8080, '0.0.0.0');

Copyright

Dominik Zogg 2021