A uWebSockets.js req/res psr-htt-message bridge.
- node: 14
- @chubbyjs/psr-http-factory: ^1.1.0
- @chubbyjs/psr-http-message: ^1.2.1
- cookie: ^0.4.1
- qs: ^6.10.1
- uWebSockets.js: github:uNetworking/uWebSockets.js#v20.6.0
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
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');
}
});
Dominik Zogg 2021