1.2.0 • Published 10 months ago

@chubbyts/chubbyts-node-http-bridge v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

chubbyts-node-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 node req/res http bridge.

Requirements

Installation

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

npm i @chubbyts/chubbyts-node-http-bridge@^1.2.0

Usage

import {
  createServerRequestFactory,
  createStreamFromResourceFactory,
  createUriFactory,
} from '@chubbyts/chubbyts-http/dist/message-factory';
import { createServer, IncomingMessage, ServerResponse } from 'http';
import { createNodeToServerRequestFactory, createResponseToNodeEmitter } from '@chubbyts/chubbyts-node-http-bridge/dist/node-http';

const app = ...;

const nodeToServerRequestFactory = createNodeToServerRequestFactory(
  createUriFactory(),
  createServerRequestFactory(),
  createStreamFromResourceFactory(),
);

const responseToNodeEmitter = createResponseToNodeEmitter();

const server = createServer(async (req: IncomingMessage, res: ServerResponse) => {
  responseToNodeEmitter(await app(nodeToServerRequestFactory(req)), res);
});

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

server.listen(port, host, () => {
  console.log(`Listening to ${host}:${port}`);
});

Copyright

2023 Dominik Zogg

1.2.0

10 months ago

1.1.1

10 months ago

1.1.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

2 years ago