A node req/res psr-htt-message bridge.
- node: 12
- @chubbyjs/psr-http-factory: ^1.1.0
- @chubbyjs/psr-http-message: ^1.2.1
- cookie: ^0.4.1
- qs: ^6.10.1
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
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');
Dominik Zogg 2021