heroiclabs / nakama-js

JavaScript client for Nakama server written in TypeScript.
https://heroiclabs.com/docs/nakama/client-libraries/javascript/
Apache License 2.0
182 stars 54 forks source link

Possible Bug in server to server RPC calls #162

Open delasource opened 1 year ago

delasource commented 1 year ago

The apiClient.rpcFunc2 function makes a GET call and i'm not sure why it does. The “payload” query param seems to be ignored in the GET case, making httpkey-requests totally pointless and the library actually useless. I may be doing something wrong, but i can’t find any hint in the documentation.

Reproduce:

Consider the following RPC: (typescript runtime)

initializer.registerRpc('pong',  (ctx, logger, nk, payload) => {
  return JSON.stringify({ my_payload_is: payload });
});

This POST call works:

$ curl "http://127.0.0.1:7350/v2/rpc/pong?http_key=defaulthttpkey" -H 'Content-Type: application/json' -H 'Accept: application/json' -X POST -d "\"money\""
{"payload":"{\"my_payload_is\":\"money\"}"}

however this doesnt:

$ curl "http://127.0.0.1:7350/v2/rpc/pong?http_key=defaulthttpkey&payload=\"money\"" -H 'Content-Type: application/json' -H 'Accept: application/json' -X GET
{"payload":"{\"my_payload_is\":\"\"}"}

So i think the rpcHttpKey function (or the rpcFunc2) should also speak POST instead of GET. (the session-based RPC stuff actually uses POST and works fine)