Skip to content

Conversation

@GertSallaerts
Copy link

@GertSallaerts GertSallaerts commented Oct 23, 2018

A "light" alternative to #991. This simply allows us to pass in two options: createWsClientTransformStream and/or createWsServerTransformStream. Implementation of parsing and/or transforming the messages is left up to the user.

It's also a solution to #1203

@GertSallaerts GertSallaerts force-pushed the feature/ws-transform-streams branch 2 times, most recently from fc73b3b to 6330fad Compare October 23, 2018 09:52
@fanfare
Copy link

fanfare commented Feb 18, 2019

Is there any progress with this? I'd really like to implement this in something I'm working on, but can't really figure out how to manipulate the frames after a connection has been established.

@brickbite
Copy link

hi @GertSallaerts, wondering if you have an example of the function that returns a duplex stream (and an example of the duplex stream implementation). I'm testing this locally and trying to get it to work, but figuring out streams at the moment.

@GertSallaerts
Copy link
Author

@brickbite the logic to set this up is not that straightforward so I created a separate repo for it. You can find it here: https://github.com/GertSallaerts/ws-transform-stream

I've not had time to complete the documentation or test the code yet, but I hope it can help you in the right direction.

It will probably be something along these lines for use with node-http-proxy

const http = require('http');
const { createProxyServer } = require('http-proxy');
const WsTransformStream = require('@gertt/ws-transform-stream');

const server = http.createServer();
const proxy = createProxyServer({});

function transform(message) {
    return message.toUpperCase();
}

function createWsClientTransformStream(req) {
    return WsTransformStream.fromUpgradeRequest(req, { transform });
};

server.on('upgrade', (req, socket, head) => {
    proxy.ws(req, socket, head, {
        /* ...yourOptions, */
        createWsClientTransformStream,
    });
});

server.listen(3000);

@brickbite
Copy link

@GertSallaerts thank you very much for the reference, I'll see if I can make anything of it

@fanfare
Copy link

fanfare commented Feb 28, 2019

Yes! can confirm it works. thanks so much @GertSallaerts

@GertSallaerts
Copy link
Author

@fanfare @brickbite I published it on NPM as well in case you guys are interested in using it as a library. You're welcome to report any issues or suggestions on the GitHub repo.

@kindermax
Copy link

Hi, do you have any plans to merge this PR? This is quite a useful feature.

@claudio-viola
Copy link

merge please

roderik added a commit to settlemint-archive/node-http-proxy that referenced this pull request Nov 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants