Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Illisible data in websocket #297

Open
AxelROGET opened this issue Nov 16, 2023 · 0 comments
Open

Illisible data in websocket #297

AxelROGET opened this issue Nov 16, 2023 · 0 comments

Comments

@AxelROGET
Copy link

I'm attempting to intercept data from WebSocket, but the data appears to be unreadable (it's a buffer). When I attempt to use toString(), I receive something like ���mlL�� and the WebSocket just doesn't work when I use socket.setEncoding().

I've tried to retrieve the socket from proxyReq, socket, server.on("upgrade") but the result remains the same (even is the Buffer are differents).

const express = require("express");
const { createProxyMiddleware } = require("http-proxy-middleware");


const app = express();

// Configuration :
const PORT = 3000;
const HOST = "localhost";
const API_SERVICE_URL = "http://192.168.1.197:8123";

const proxy = createProxyMiddleware({
    target: API_SERVICE_URL,
    changeOrigin: true,
    pathRewrite: {
        [`^/`]: '',
    },
    ws: true,
    logLevel: 'debug',
    onProxyReqWs: (proxyReq, req, socket) => {
        proxyReq.on('upgrade', (req, socket, head) => {
            proxy.upgrade(req, socket, head);

            // socket.setEncoding('utf-8')

            socket.on('data', data => {
                console.log(data);
                const buff = Buffer.from(data);
                console.log(buff.toString())
            })
        })
    }

})

// Proxy endpoints
app.use('/', proxy);

// Start the Proxy
const server = app.listen(PORT, HOST, () => {
    console.log(`Starting Proxy at ${HOST}:${PORT}`);
});

Do you have any advice on what I should do?
Thanks!

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

No branches or pull requests

1 participant