Best practice for building the WebSocket client using Node.js

bozz-cath4 years ago

Hi, I would like to ask about the way to implement the WebSocket client as receiver on Node.js. It like a another Back-end server.

I'm quite confuse about the Session cookie for authorized the WebSocket,
It's seem I have to login with browser for getting it. right? (JSESSION=xxxx)

As I know the /api/session (POST) didn't return a session cookie right?

So Is possible way to make it automatically?
For Instance, I just login one time then use the API to refresh the expired session time?

Anton Tananaev4 years ago

All calls return cookie, including session.

bozz-cath4 years ago

Thanks for reply,
I have stuck with the POST create /api/session

    try {
        var bodyData = new FormData();
        bodyData.append('email', '<email-user>')
        bodyData.append('password', <password>')
        
        let response = await axios.post('http://<host>/api/session', 
                             bodyData , 
                                 { headers: {
                                           'Content-Type': 'application/x-www-form-urlencoded'
                                   }, 
        console.log(response)

But I got 400 everytime, What wrong with it?

Anton Tananaev4 years ago

What's the response message?

bozz-cath4 years ago

Thanks for reply, But now It's work!!
I just misunderstand the axios parameter (TT)