0

when I make a request to my API, my code is using a web socket (Ws https://www.npmjs.com/package/ws) that I have connected to another server (port 7777). The web socket is doing its job correctly, sending correctly and receiving correctly what I'm asking for, however once I get the message from the web socket I would like to send the data from the web socket via my API using response.ok but it doesn't return anything (screen below).

Code:

public async embed_builder ({ request, response }: HttpContextContract) {
    const payload = request.body();

    Ws.ws.on("open", () => {
      Ws.ws.send(JSON.stringify({
        socket_name: "embed-builder",
        channel_id: payload.channel_id,
        embed: payload.embed
      }));

      Ws.ws.on("message", (data: Buffer) => {
        const message = JSON.parse(data.toString());
        // ^ message is perfectly defined 👍
        if (message.socket_name === "embed-builder") {
          // everything is ok 👍
          if (!message.ok) return response.badRequest({ error: { message: message.statusText }, code: message.status });
          // everything is ok 👍

          return response.ok("OK")
          // ^ I don't receive anything and I don't know if it works 👎
        }
      });
    });
  }

No reponse: No response

2
  • so you're getting a 200 OK status code but with an empty body, right? Commented Aug 19, 2022 at 15:15
  • yes it is exactly that Commented Aug 31, 2022 at 15:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.