@chubbyts/chubbyts-http-node-bridge
v1.2.0
Published
A node req/res http bridge.
Downloads
543
Readme
chubbyts-http-node-bridge
Description
A node req/res http bridge.
Requirements
- node: 16
- @chubbyts/chubbyts-http-types: ^1.2.3
Installation
Through NPM as @chubbyts/chubbyts-http-node-bridge.
npm i @chubbyts/chubbyts-http-node-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-http-node-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
2024 Dominik Zogg