node.js

[Node.js] grpc 통신 WebSocket POST Request 방법

판교너굴맨 2022. 3. 8. 11:26

작업 도중 webSocket으로 POST 요청을 해야하는 상황이 생겼다.

const ws = new WebSocket('url')
ws.onopen = () => console.log("connected!!");
ws.onmessage = (msg) => {
	console.log(msg.data);
};

위와 같이 GET과 같은 방법으로 요청을 보내면 

"Method Not Allowed" 라는 메세지가 반환된다..

 

그럼 POST 요청은 보낼 수 없는 걸까??

const ws = new WebSocket('url?method=POST')
ws.onopen = () => {
    console.log("connected!!")
    ws.send(prams)
};
ws.onmessage = (msg) => {
    console.log(msg.data);
};

url에 ?method=POST를 추가해주는 간단한 방법이 있었다..  이문제로 시간을 상당히 사용했다.

 

참고

https://github.com/tmc/grpc-websocket-proxy/issues/27

 

Doesn't work with grpc-gateway/v2/runtime · Issue #27 · tmc/grpc-websocket-proxy

Doesn't work with grpc-gateway/v2/runtime I was unable to start with v2. Is there an example of the work? The connection attempt ends { "code": 12, "message": "Method N...

github.com